Skip to content

Commit

Permalink
properly collect entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Oct 18, 2024
1 parent 65e4c14 commit 2734900
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<ItemStack, BlockPos>> destroyedBlocks = new ObjectArrayList<>();
for (BlockPos pos : affectedBlocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ladysnake/blast/mixin/ExplosionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2734900

Please sign in to comment.