use of cn.nukkit.blockentity.BlockEntity in project Nukkit by Nukkit.
the class BlockFlowerPot method getDrops.
@Override
public Item[] getDrops(Item item) {
boolean dropInside = false;
int insideID = 0;
int insideMeta = 0;
BlockEntity blockEntity = getLevel().getBlockEntity(this);
if (blockEntity instanceof BlockEntityFlowerPot) {
dropInside = true;
insideID = blockEntity.namedTag.getShort("item");
insideMeta = blockEntity.namedTag.getInt("data");
}
if (dropInside) {
return new Item[] { new ItemFlowerPot(), Item.get(insideID, insideMeta, 1) };
} else {
return new Item[] { new ItemFlowerPot() };
}
}
use of cn.nukkit.blockentity.BlockEntity in project Nukkit by Nukkit.
the class BlockFurnaceBurning method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
BlockEntity t = this.getLevel().getBlockEntity(this);
BlockEntityFurnace furnace;
if (t instanceof BlockEntityFurnace) {
furnace = (BlockEntityFurnace) t;
} else {
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.FURNACE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
furnace = new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
}
if (furnace.namedTag.contains("Lock") && furnace.namedTag.get("Lock") instanceof StringTag) {
if (!furnace.namedTag.getString("Lock").equals(item.getCustomName())) {
return true;
}
}
player.addWindow(furnace.getInventory());
}
return true;
}
use of cn.nukkit.blockentity.BlockEntity in project Nukkit by Nukkit.
the class BlockItemFrame method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity;
if (itemFrame.getItem().getId() == Item.AIR) {
// We can't use Item.get(item.getId(), item.getDamage(), 1) because
// we need to keep the item's NBT tags
// So we clone the item
Item itemOnFrame = item.clone();
// Change it to only one item (if we keep +1, visual glitches will happen)
itemOnFrame.setCount(1);
// And then we set it on the item frame
itemFrame.setItem(itemOnFrame);
// The item will be removed from the player's hand a few lines ahead
this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ADD_ITEM);
if (player != null && player.isSurvival()) {
int count = item.getCount();
if (count-- <= 0) {
player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
return true;
}
item.setCount(count);
player.getInventory().setItemInHand(item);
}
} else {
int itemRot = itemFrame.getItemRotation();
if (itemRot >= 7) {
itemRot = 0;
} else {
itemRot++;
}
itemFrame.setItemRotation(itemRot);
this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ROTATE_ITEM);
}
return true;
}
use of cn.nukkit.blockentity.BlockEntity in project Nukkit by Nukkit.
the class BlockJukebox method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
if (blockEntity == null || !(blockEntity instanceof BlockEntityJukebox)) {
blockEntity = this.createBlockEntity();
}
BlockEntityJukebox jukebox = (BlockEntityJukebox) blockEntity;
if (jukebox.getRecordItem().getId() != 0) {
jukebox.dropItem();
} else if (item instanceof ItemRecord) {
jukebox.setRecordItem(item);
jukebox.play();
player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex());
}
return false;
}
use of cn.nukkit.blockentity.BlockEntity in project Nukkit by Nukkit.
the class BlockSkull method getDrops.
@Override
public Item[] getDrops(Item item) {
BlockEntity blockEntity = getLevel().getBlockEntity(this);
int dropMeta = 0;
if (blockEntity != null)
dropMeta = blockEntity.namedTag.getByte("SkullType");
return new Item[] { new ItemSkull(dropMeta) };
}
Aggregations