Search in sources :

Example 1 with GlowDispenser

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

the class BlockDispenser method trigger.

public void trigger(GlowBlock block) {
    BlockEntity te = block.getBlockEntity();
    if (!(te instanceof DispenserEntity)) {
        return;
    }
    DispenserEntity teDispenser = (DispenserEntity) te;
    GlowDispenser dispenser = (GlowDispenser) teDispenser.getState();
    dispenser.dispense();
}
Also used : DispenserEntity(net.glowstone.block.entity.DispenserEntity) GlowDispenser(net.glowstone.block.state.GlowDispenser) BlockEntity(net.glowstone.block.entity.BlockEntity)

Example 2 with GlowDispenser

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

the class EmptyBucketDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowDispenser dispenser = (GlowDispenser) block.getState();
    GlowBlock target = block.getRelative(BlockDispenser.getFacing(block));
    BlockLiquid liquid = collectableLiquidAtBlock(target);
    if (liquid == null) {
        return super.dispenseStack(block, stack);
    }
    Material bucket = liquid.getBucketType();
    target.setType(Material.AIR);
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() == 0) {
        stack.setAmount(1);
        stack.setType(bucket);
    } else {
        ItemStack toPlace = new ItemStack(bucket);
        ItemStack remaining = dispenser.placeInDispenser(toPlace);
        if (remaining != null) {
            defaultBehavior.dispense(block, remaining);
        }
    }
    return stack;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) GlowDispenser(net.glowstone.block.state.GlowDispenser) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GlowDispenser (net.glowstone.block.state.GlowDispenser)2 GlowBlock (net.glowstone.block.GlowBlock)1 BlockLiquid (net.glowstone.block.blocktype.BlockLiquid)1 BlockEntity (net.glowstone.block.entity.BlockEntity)1 DispenserEntity (net.glowstone.block.entity.DispenserEntity)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1