Search in sources :

Example 1 with BlockEntityFlowerPot

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() };
    }
}
Also used : Item(cn.nukkit.item.Item) ItemFlowerPot(cn.nukkit.item.ItemFlowerPot) BlockEntity(cn.nukkit.blockentity.BlockEntity) BlockEntityFlowerPot(cn.nukkit.blockentity.BlockEntityFlowerPot)

Example 2 with BlockEntityFlowerPot

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;
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntityFlowerPot(cn.nukkit.blockentity.BlockEntityFlowerPot)

Example 3 with BlockEntityFlowerPot

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;
}
Also used : BlockEntity(cn.nukkit.blockentity.BlockEntity) BlockEntityFlowerPot(cn.nukkit.blockentity.BlockEntityFlowerPot)

Aggregations

BlockEntityFlowerPot (cn.nukkit.blockentity.BlockEntityFlowerPot)3 BlockEntity (cn.nukkit.blockentity.BlockEntity)2 Item (cn.nukkit.item.Item)1 ItemFlowerPot (cn.nukkit.item.ItemFlowerPot)1 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 Tag (cn.nukkit.nbt.tag.Tag)1