use of cn.nukkit.blockentity.BlockEntityFlowerPot 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.BlockEntityFlowerPot in project Nukkit by Nukkit.
the class BlockFlowerPot method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (face != BlockFace.UP)
return false;
CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.FLOWER_POT).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putShort("item", 0).putInt("data", 0);
if (item.hasCustomBlockData()) {
for (Tag aTag : item.getCustomBlockData().getAllTags()) {
nbt.put(aTag.getName(), aTag);
}
}
new BlockEntityFlowerPot(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
this.getLevel().setBlock(block, this, true, true);
return true;
}
use of cn.nukkit.blockentity.BlockEntityFlowerPot in project Nukkit by Nukkit.
the class BlockFlowerPot method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
BlockEntity blockEntity = getLevel().getBlockEntity(this);
if (!(blockEntity instanceof BlockEntityFlowerPot))
return false;
if (blockEntity.namedTag.getShort("item") != 0 || blockEntity.namedTag.getInt("mData") != 0)
return false;
int itemID;
int itemMeta;
if (!canPlaceIntoFlowerPot(item.getId())) {
if (!canPlaceIntoFlowerPot(item.getBlock().getId())) {
return true;
}
itemID = item.getBlock().getId();
itemMeta = item.getDamage();
} else {
itemID = item.getId();
itemMeta = item.getDamage();
}
blockEntity.namedTag.putShort("item", itemID);
blockEntity.namedTag.putInt("data", itemMeta);
this.setDamage(1);
this.getLevel().setBlock(this, this, true);
((BlockEntityFlowerPot) blockEntity).spawnToAll();
if (player.isSurvival()) {
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item.getCount() > 0 ? item : Item.get(Item.AIR));
}
return true;
}
Aggregations