cn.nukkit.blockentity.BlockEntityFlowerPot Java Examples

The following examples show how to use cn.nukkit.blockentity.BlockEntityFlowerPot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private void registerBlockEntities() {
    BlockEntity.registerBlockEntity(BlockEntity.FURNACE, BlockEntityFurnace.class);
    BlockEntity.registerBlockEntity(BlockEntity.CHEST, BlockEntityChest.class);
    BlockEntity.registerBlockEntity(BlockEntity.SIGN, BlockEntitySign.class);
    BlockEntity.registerBlockEntity(BlockEntity.ENCHANT_TABLE, BlockEntityEnchantTable.class);
    BlockEntity.registerBlockEntity(BlockEntity.SKULL, BlockEntitySkull.class);
    BlockEntity.registerBlockEntity(BlockEntity.FLOWER_POT, BlockEntityFlowerPot.class);
    BlockEntity.registerBlockEntity(BlockEntity.BREWING_STAND, BlockEntityBrewingStand.class);
    BlockEntity.registerBlockEntity(BlockEntity.ITEM_FRAME, BlockEntityItemFrame.class);
    BlockEntity.registerBlockEntity(BlockEntity.CAULDRON, BlockEntityCauldron.class);
    BlockEntity.registerBlockEntity(BlockEntity.ENDER_CHEST, BlockEntityEnderChest.class);
    BlockEntity.registerBlockEntity(BlockEntity.BEACON, BlockEntityBeacon.class);
    BlockEntity.registerBlockEntity(BlockEntity.SHULKER_BOX, BlockEntityShulkerBox.class);
    BlockEntity.registerBlockEntity(BlockEntity.MOB_SPAWNER, BlockEntityMobSpawner.class);
    BlockEntity.registerBlockEntity(BlockEntity.DISPENSER, BlockEntityDispenser.class);
    BlockEntity.registerBlockEntity(BlockEntity.DROPPER, BlockEntityDropper.class);
    BlockEntity.registerBlockEntity(BlockEntity.COMMAND_BLOCK, BlockEntityCommandBlock.class);
    BlockEntity.registerBlockEntity(BlockEntity.BANNER, BlockEntityBanner.class);
}
 
Example #2
Source File: BlockFlowerPot.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: BlockFlowerPot.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@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()
        };
    }
}
 
Example #4
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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);
        }
    }
    BlockEntityFlowerPot flowerPot = (BlockEntityFlowerPot) BlockEntity.createBlockEntity(BlockEntity.FLOWER_POT, getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
    if (flowerPot == null) return false;

    this.getLevel().setBlock(block, this, true, true);
    return true;
}
 
Example #5
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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()
        };
    }
}
 
Example #6
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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()
        };
    }
}
 
Example #8
Source File: BlockFlowerPot.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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.meta = 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;
}
 
Example #9
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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;
}