use of me.deecaad.weaponmechanics.weapon.explode.raytrace.TraceCollision in project MechanicsMain by WeaponMechanics.
the class ExplosionExposure method canSee.
/**
* Determines if the given entity can see the given <code>Location</code>.
*
* @param originLoc The point to check if the entity can see
* @param entity The entity to check against
* @param fov The field of view of the entity
* @return true if the entity can see the origin
*/
default boolean canSee(@Nonnull Location originLoc, @Nonnull LivingEntity entity, double fov) {
// Get the vector between the entity and origin, and the player's eye
// vector, and determine the angle between the 2 vectors.
Vector origin = originLoc.toVector();
Vector end = entity.getEyeLocation().toVector();
Vector direction = entity.getLocation().getDirection();
Vector between = origin.clone().subtract(end);
double angle = VectorUtil.getAngleBetween(direction, between);
// then we need to do more calculations
if (angle > fov) {
return false;
}
Ray ray = new Ray(originLoc.getWorld(), origin, end, between.length());
TraceCollision collision = new TraceCollision(BLOCK_OR_ENTITY) {
@Override
public boolean canHit(Block block) {
String name = block.getType().name();
// GLASS
if (name.endsWith("GLASS") || name.endsWith("PANE")) {
return false;
} else // LEAVES
if (name.endsWith("LEAVES")) {
return false;
} else // OAK_FENCE
if (name.endsWith("FENCE") || name.endsWith("FENCE_GATE")) {
return false;
} else if (name.equals("SLIME_BLOCK")) {
return false;
} else {
return WeaponCompatibilityAPI.getWeaponCompatibility().getHitBox(block) != null;
}
}
@Override
public boolean canHit(Entity entity1) {
return !entity1.equals(entity);
}
};
TraceResult result = ray.trace(collision, 0.2);
// origin, than the entity can see the explosion
return result.isEmpty();
}
Aggregations