Search in sources :

Example 1 with GlowFlowerPot

use of net.glowstone.block.state.GlowFlowerPot in project Glowstone by GlowstoneMC.

the class BlockFlowerPot method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof FlowerPot)) {
        warnMaterialData(FlowerPot.class, data);
        return false;
    }
    if (state instanceof GlowFlowerPot) {
        GlowFlowerPot pot = (GlowFlowerPot) state;
        ItemStack heldItem = player.getItemInHand();
        // Only change contents if there is none and if the held item is valid pot contents.
        if (pot.getContents() == null && heldItem != null && isValidContents(heldItem.getData())) {
            // Null-check in isValidContents.
            pot.setContents(heldItem.getData().clone());
            return pot.update();
        }
    }
    return false;
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot) FlowerPot(org.bukkit.material.FlowerPot) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot)

Example 2 with GlowFlowerPot

use of net.glowstone.block.state.GlowFlowerPot in project Glowstone by GlowstoneMC.

the class BlockFlowerPot method getDrops.

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    List<ItemStack> drops = new LinkedList<>(Arrays.asList(new ItemStack(Material.FLOWER_POT)));
    GlowBlockState state = block.getState();
    if (state instanceof GlowFlowerPot) {
        MaterialData contents = ((GlowFlowerPot) state).getContents();
        if (contents != null) {
            drops.add(new ItemStack(contents.getItemType(), 1, contents.getData()));
        }
    }
    return Collections.unmodifiableList(drops);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 ItemStack (org.bukkit.inventory.ItemStack)2 MaterialData (org.bukkit.material.MaterialData)2 FlowerPot (org.bukkit.material.FlowerPot)1