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