Search in sources :

Example 6 with BlockEntity

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

Example 7 with BlockEntity

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

Example 8 with BlockEntity

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

Example 9 with BlockEntity

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

Example 10 with BlockEntity

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

Aggregations

BlockEntity (cn.nukkit.blockentity.BlockEntity)32 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)13 Entity (cn.nukkit.entity.Entity)7 Player (cn.nukkit.Player)6 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)6 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)6 StringTag (cn.nukkit.nbt.tag.StringTag)6 IOException (java.io.IOException)6 Item (cn.nukkit.item.Item)5 FullChunk (cn.nukkit.level.format.FullChunk)5 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)4 ListTag (cn.nukkit.nbt.tag.ListTag)4 BinaryStream (cn.nukkit.utils.BinaryStream)4 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)3 ArrayList (java.util.ArrayList)3 BlockEntityComparator (cn.nukkit.blockentity.BlockEntityComparator)2 BlockEntityFlowerPot (cn.nukkit.blockentity.BlockEntityFlowerPot)2 Tag (cn.nukkit.nbt.tag.Tag)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)2