use of org.bukkit.event.block.BlockDispenseEvent in project Glowstone by GlowstoneMC.
the class DefaultDispenseBehavior method doDispense.
private void doDispense(GlowBlock block, ItemStack items, int power, BlockFace facing, Vector target) {
double x = target.getX();
double y = target.getY();
double z = target.getZ();
if (facing.getModY() != 0) {
y -= 0.125;
} else {
y -= 0.15625;
}
double velocity = random.nextDouble() * 0.1 + 0.2;
double velocityX = facing.getModX() * velocity;
double velocityY = 0.2;
double velocityZ = facing.getModZ() * velocity;
velocityX += random.nextGaussian() * 0.0075 * power;
velocityY += random.nextGaussian() * 0.0075 * power;
velocityZ += random.nextGaussian() * 0.0075 * power;
BlockDispenseEvent dispenseEvent = new BlockDispenseEvent(block, items, new Vector(velocityX, velocityY, velocityZ));
EventFactory.callEvent(dispenseEvent);
if (!dispenseEvent.isCancelled()) {
GlowItem item = new GlowItem(new Location(block.getWorld(), x, y, z), dispenseEvent.getItem());
item.setVelocity(dispenseEvent.getVelocity());
}
}
Aggregations