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();
}
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;
}
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;
}
Aggregations