Search in sources :

Example 1 with BlockDispenseEvent

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());
    }
}
Also used : BlockDispenseEvent(org.bukkit.event.block.BlockDispenseEvent) Vector(org.bukkit.util.Vector) GlowItem(net.glowstone.entity.objects.GlowItem) Location(org.bukkit.Location)

Aggregations

GlowItem (net.glowstone.entity.objects.GlowItem)1 Location (org.bukkit.Location)1 BlockDispenseEvent (org.bukkit.event.block.BlockDispenseEvent)1 Vector (org.bukkit.util.Vector)1