Search in sources :

Example 1 with EntityMovementChangePacket

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);
        }
    }
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) LootContextParams(net.minecraft.world.level.storage.loot.parameters.LootContextParams) AABB(net.minecraft.world.phys.AABB) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ServerLevel(net.minecraft.server.level.ServerLevel) EntityMovementChangePacket(slimeknights.tconstruct.tools.network.EntityMovementChangePacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) Lists(com.google.common.collect.Lists) LootContext(net.minecraft.world.level.storage.loot.LootContext) DamageSource(net.minecraft.world.damagesource.DamageSource) SoundEvents(net.minecraft.sounds.SoundEvents) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TinkerNetwork(slimeknights.tconstruct.common.network.TinkerNetwork) Predicate(java.util.function.Predicate) TickEvent(net.minecraftforge.event.TickEvent) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) Entity(net.minecraft.world.entity.Entity) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) FluidState(net.minecraft.world.level.material.FluidState) EntitySelector(net.minecraft.world.entity.EntitySelector) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ParticleTypes(net.minecraft.core.particles.ParticleTypes) Collections(java.util.Collections) EFLNExplosion(slimeknights.tconstruct.gadgets.entity.EFLNExplosion) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) EntityMovementChangePacket(slimeknights.tconstruct.tools.network.EntityMovementChangePacket) Vec3(net.minecraft.world.phys.Vec3) ServerPlayer(net.minecraft.server.level.ServerPlayer) AABB(net.minecraft.world.phys.AABB)

Aggregations

Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Predicate (java.util.function.Predicate)1 BlockPos (net.minecraft.core.BlockPos)1 ParticleTypes (net.minecraft.core.particles.ParticleTypes)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 SoundEvents (net.minecraft.sounds.SoundEvents)1 SoundSource (net.minecraft.sounds.SoundSource)1 DamageSource (net.minecraft.world.damagesource.DamageSource)1 Entity (net.minecraft.world.entity.Entity)1 EntitySelector (net.minecraft.world.entity.EntitySelector)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 Block (net.minecraft.world.level.block.Block)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 FluidState (net.minecraft.world.level.material.FluidState)1