From 27349000b03484ace76aba21e5f0a7294aee4487 Mon Sep 17 00:00:00 2001 From: MoriyaShiine <45156123+MoriyaShiine@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:44:52 -0500 Subject: [PATCH] properly collect entities --- .../ladysnake/blast/common/world/CustomExplosion.java | 9 --------- .../ladysnake/blast/common/world/EnderExplosion.java | 1 - .../ladysnake/blast/common/world/KnockbackExplosion.java | 1 - src/main/java/ladysnake/blast/mixin/ExplosionMixin.java | 8 ++++++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/ladysnake/blast/common/world/CustomExplosion.java b/src/main/java/ladysnake/blast/common/world/CustomExplosion.java index d475a00..d6aca86 100644 --- a/src/main/java/ladysnake/blast/common/world/CustomExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/CustomExplosion.java @@ -9,7 +9,6 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -21,7 +20,6 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.explosion.Explosion; @@ -40,7 +38,6 @@ public CustomExplosion(World world, Entity entity, double x, double y, double z, @Override public void affectWorld(boolean particles) { - collectEntities(); world.playSound(null, x, y, z, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4, (1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F); boolean destroy = destructionType != DestructionType.KEEP; if (particles) { @@ -141,12 +138,6 @@ public void affectWorld(boolean particles) { } } - public void collectEntities() { - for (BlockPos pos : affectedBlocks) { - affectedEntities.addAll(world.getEntitiesByClass(LivingEntity.class, new Box(pos).expand(1), LivingEntity::isAlive)); - } - } - public boolean shouldDamageEntities() { return true; } diff --git a/src/main/java/ladysnake/blast/common/world/EnderExplosion.java b/src/main/java/ladysnake/blast/common/world/EnderExplosion.java index 4a64e2a..367ac19 100644 --- a/src/main/java/ladysnake/blast/common/world/EnderExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/EnderExplosion.java @@ -33,7 +33,6 @@ public EnderExplosion(World world, Entity entity, double x, double y, double z, @Override public void affectWorld(boolean particles) { BlockPos source = BlockPos.ofFloored(new Vec3d(x, y, z)); - collectEntities(); world.playSound(null, x, y, z, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 4, (1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.9F); ObjectArrayList> destroyedBlocks = new ObjectArrayList<>(); for (BlockPos pos : affectedBlocks) { diff --git a/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java b/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java index c897766..b04340e 100644 --- a/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java @@ -16,7 +16,6 @@ public KnockbackExplosion(World world, Entity entity, double x, double y, double @Override public void affectWorld(boolean particles) { Vec3d source = new Vec3d(x, y, z); - collectEntities(); if (particles) { for (int i = 0; i < 500; i++) { world.addParticle(ParticleTypes.SNEEZE, this.x, this.y, this.z, this.random.nextGaussian() / 5, this.random.nextGaussian() / 5, this.random.nextGaussian() / 5); diff --git a/src/main/java/ladysnake/blast/mixin/ExplosionMixin.java b/src/main/java/ladysnake/blast/mixin/ExplosionMixin.java index 6d9972c..73e36b4 100644 --- a/src/main/java/ladysnake/blast/mixin/ExplosionMixin.java +++ b/src/main/java/ladysnake/blast/mixin/ExplosionMixin.java @@ -49,8 +49,12 @@ public class ExplosionMixin { } @WrapWithCondition(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V")) - private boolean blast$enderItemVelocity(Entity instance, Vec3d velocity) { - return !((Object) this instanceof EnderExplosion); + private boolean blast$collect(Entity instance, Vec3d velocity) { + if ((Object) this instanceof CustomExplosion customExplosion) { + customExplosion.affectedEntities.add(instance); + return !(customExplosion instanceof EnderExplosion); + } + return true; } @Unique