cn.nukkit.block.BlockJukebox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitDifference;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityJukebox;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemRecord;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* @author CreeperFace
* @since 7.8.2017
*/
@PowerNukkitDifference(since = "1.4.0.0-PN", info = "Implements BlockEntityHolder only in PowerNukkit")
public class BlockJukebox extends BlockSolid implements BlockEntityHolder {
public BlockJukebox() {
// Does nothing
}
@Override
public String getName() {
return "Jukebox";
}
@Override
public int getId() {
return JUKEBOX;
}
@Since("1.4.0.0-PN")
@PowerNukkitOnly
@Nonnull
@Override
public Class extends BlockEntityJukebox> getBlockEntityClass() {
return BlockEntityJukebox.class;
}
@PowerNukkitOnly
@Since("1.4.0.0-PN")
@Nonnull
@Override
public String getBlockEntityType() {
return BlockEntity.JUKEBOX;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public Item toItem() {
return new ItemBlock(this, 0);
}
@Override
public double getHardness() {
return 1;
}
@Override
public boolean onActivate(@Nonnull Item item, @Nullable Player player) {
BlockEntityJukebox jukebox = getOrCreateBlockEntity();
if (jukebox.getRecordItem().getId() != 0) {
jukebox.dropItem();
return true;
}
if (!item.isNull() && item instanceof ItemRecord) {
Item record = item.clone();
record.count = 1;
item.count--;
jukebox.setRecordItem(record);
jukebox.play();
return true;
}
return false;
}
@Override
public boolean place(@Nonnull Item item, @Nonnull Block block, @Nonnull Block target, @Nonnull BlockFace face, double fx, double fy, double fz, @Nullable Player player) {
return BlockEntityHolder.setBlockAndCreateEntity(this) != null;
}
@Override
public BlockColor getColor() {
return BlockColor.DIRT_BLOCK_COLOR;
}
}