Search in sources :

Example 1 with GlowDispenser

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

the class BlockDispenser method trigger.

/**
 * Dispense an item from the given block if it's a dispenser.
 *
 * @param block the dispenser block
 */
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.entity.state.GlowDispenser) BlockEntity(net.glowstone.block.entity.BlockEntity)

Example 2 with GlowDispenser

use of net.glowstone.block.entity.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) {
            INSTANCE.dispense(block, remaining);
        }
    }
    return stack;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) GlowDispenser(net.glowstone.block.entity.state.GlowDispenser) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with GlowDispenser

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

the class ProjectileDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowWorld world = block.getWorld();
    Vector position = BlockDispenser.getDispensePosition(block);
    BlockFace face = BlockDispenser.getFacing(block);
    Projectile entity = projectileCreator.apply(new Location(world, position.getX(), position.getY(), position.getZ()), stack);
    entity.setShooter(new GlowDispenser(block));
    entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() < 1) {
        return null;
    }
    return stack;
}
Also used : GlowDispenser(net.glowstone.block.entity.state.GlowDispenser) BlockFace(org.bukkit.block.BlockFace) GlowWorld(net.glowstone.GlowWorld) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location)

Aggregations

GlowDispenser (net.glowstone.block.entity.state.GlowDispenser)3 GlowWorld (net.glowstone.GlowWorld)1 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 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 BlockFace (org.bukkit.block.BlockFace)1 Projectile (org.bukkit.entity.Projectile)1 ItemStack (org.bukkit.inventory.ItemStack)1 Vector (org.bukkit.util.Vector)1