Search in sources :

Example 1 with ProjectileHitEvent

use of org.bukkit.event.entity.ProjectileHitEvent in project Glowstone by GlowstoneMC.

the class GlowEntity method pulsePhysics.

protected void pulsePhysics() {
    // The pending location and the block at that location
    Location pendingLocation = location.clone().add(velocity);
    Block pendingBlock = pendingLocation.getBlock();
    if (pendingBlock.getType().isSolid()) {
        Location pendingLocationX = location.clone().add(velocity.getX(), 0, 0);
        if (pendingLocationX.getBlock().getType().isSolid()) {
            velocity.setX(0);
        }
        Location pendingLocationY = location.clone().add(0, velocity.getY(), 0);
        if (pendingLocationY.getBlock().getType().isSolid()) {
            velocity.setY(0);
        }
        Location pendingLocationZ = location.clone().add(0, 0, velocity.getZ());
        if (pendingLocationZ.getBlock().getType().isSolid()) {
            velocity.setZ(0);
        }
        if (this instanceof Projectile) {
            EventFactory.getInstance().callEvent(new ProjectileHitEvent((Projectile) this, pendingBlock));
        }
        collide(pendingBlock);
    } else {
        if (hasFriction()) {
            // apply friction and gravity
            if (location.getBlock().getType() == Material.WATER) {
                velocity.multiply(liquidDrag);
                velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            } else if (location.getBlock().getType() == Material.LAVA) {
                velocity.multiply(liquidDrag - 0.3);
                velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            } else {
                if (applyDragBeforeAccel) {
                    velocity.setY(airDrag * velocity.getY() + getGravityAccel().getY());
                } else {
                    velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY()));
                }
                if (isOnGround()) {
                    velocity.setX(velocity.getX() * slipMultiplier);
                    velocity.setY(0);
                    velocity.setZ(velocity.getZ() * slipMultiplier);
                } else {
                    velocity.setX(velocity.getX() * airDrag);
                    velocity.setZ(velocity.getZ() * airDrag);
                }
            }
        } else if (hasGravity() && !isOnGround()) {
            switch(location.getBlock().getType()) {
                case WATER:
                case LAVA:
                    velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
                    break;
                default:
                    velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
            }
        }
        setRawLocation(pendingLocation);
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Block(org.bukkit.block.Block) Location(org.bukkit.Location) Projectile(org.bukkit.entity.Projectile)

Example 2 with ProjectileHitEvent

use of org.bukkit.event.entity.ProjectileHitEvent in project Glowstone by GlowstoneMC.

the class GlowProjectile method pulsePhysics.

@Override
protected void pulsePhysics() {
    if (boundingBox != null) {
        Vector size = boundingBox.getSize();
        for (Entity entity : world.getNearbyEntities(location, size.getX(), size.getY(), size.getZ())) {
            if (entity != this && !(entity.equals(shooter))) {
                if (entity instanceof LivingEntity) {
                    EventFactory.getInstance().callEvent(new ProjectileHitEvent(this, entity));
                    collide((LivingEntity) entity);
                    break;
                }
            }
        }
    }
    super.pulsePhysics();
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) GlowEntity(net.glowstone.entity.GlowEntity) LivingEntity(org.bukkit.entity.LivingEntity) ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Vector(org.bukkit.util.Vector)

Aggregations

ProjectileHitEvent (org.bukkit.event.entity.ProjectileHitEvent)2 GlowEntity (net.glowstone.entity.GlowEntity)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Projectile (org.bukkit.entity.Projectile)1 Vector (org.bukkit.util.Vector)1