use of slimeknights.tconstruct.tools.network.EntityMovementChangePacket in project TinkersConstruct by SlimeKnights.
the class Exploder method handleEntities.
private void handleEntities() {
final Predicate<Entity> predicate = entity -> entity != null && !entity.ignoreExplosion() && EntitySelector.NO_SPECTATORS.test(entity) && EntitySelector.ENTITY_STILL_ALIVE.test(entity) && entity.position().distanceToSqr(this.x, this.y, this.z) <= this.r * this.r;
// damage and blast back entities
List<Entity> list = this.world.getEntities(this.exploder, new AABB(this.x - this.r - 1, this.y - this.r - 1, this.z - this.r - 1, this.x + this.r + 1, this.y + this.r + 1, this.z + this.r + 1), predicate);
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, this.explosion, list, this.r * 2);
for (Entity entity : list) {
// move it away from the center depending on distance and explosion strength
Vec3 dir = entity.position().subtract(this.exploder.position().add(0, -this.r / 2, 0));
double str = (this.r - dir.length()) / this.r;
str = Math.max(0.3, str);
dir = dir.normalize();
dir = dir.scale(this.explosionStrength * str * 0.3);
entity.push(dir.x, dir.y + 0.5, dir.z);
entity.hurt(DamageSource.explosion(this.explosion), (float) (str * this.explosionStrength));
if (entity instanceof ServerPlayer) {
TinkerNetwork.getInstance().sendTo(new EntityMovementChangePacket(entity), (ServerPlayer) entity);
}
}
}
Aggregations