diff --git a/src/main/java/ladysnake/blast/common/world/BlockFillingExplosion.java b/src/main/java/ladysnake/blast/common/world/BlockFillingExplosion.java index 4196bc8..324858c 100644 --- a/src/main/java/ladysnake/blast/common/world/BlockFillingExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/BlockFillingExplosion.java @@ -16,7 +16,7 @@ public BlockFillingExplosion(World world, Entity entity, double x, double y, dou @Override public void affectWorld(boolean particles) { super.affectWorld(particles); - for (BlockPos pos : affectedBlocks) { + for (BlockPos pos : getAffectedBlocks()) { if (canPlace(pos)) { BlockState state = world.getBlockState(pos); if (state.isReplaceable()) { diff --git a/src/main/java/ladysnake/blast/common/world/BonesburrierExplosion.java b/src/main/java/ladysnake/blast/common/world/BonesburrierExplosion.java index 7b3e93c..8c5b297 100644 --- a/src/main/java/ladysnake/blast/common/world/BonesburrierExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/BonesburrierExplosion.java @@ -36,7 +36,8 @@ public BonesburrierExplosion(World world, Entity entity, double x, double y, dou @Override public void collectBlocksAndDamageEntities() { - world.emitGameEvent(entity, GameEvent.EXPLODE, BlockPos.ofFloored(x, y, z)); + Vec3d source = getPosition(); + world.emitGameEvent(entity, GameEvent.EXPLODE, BlockPos.ofFloored(source.x, source.y, source.z)); Set set = new HashSet<>(); BlockPos.Mutable mutable = new BlockPos.Mutable(); for (int i = 0; i < 16; i++) { @@ -50,9 +51,9 @@ public void collectBlocksAndDamageEntities() { iX /= product; jX /= product; kX /= product; - double dX = x; - double dY = y; - double dZ = z; + double dX = source.x; + double dY = source.y; + double dZ = source.z; for (float currentPower = getPower() * (0.7f + world.random.nextFloat() * 0.6f); currentPower > 0.0f; currentPower -= 0.22500001f) { mutable.set(dX, dY, dZ); if (!world.isInBuildLimit(mutable)) { @@ -74,22 +75,21 @@ public void collectBlocksAndDamageEntities() { } } } - affectedBlocks.addAll(set); + getAffectedBlocks().addAll(set); float power = getPower() * 2; - int minX = MathHelper.floor(x - power - 1); - int maxX = MathHelper.floor(x + power + 1); - int minY = MathHelper.floor(y - power - 1); - int maxY = MathHelper.floor(y + power + 1); - int minZ = MathHelper.floor(z - power - 1); - int maxZ = MathHelper.floor(z + power + 1); - Vec3d source = new Vec3d(x, y, z); + int minX = MathHelper.floor(source.x - power - 1); + int maxX = MathHelper.floor(source.x + power + 1); + int minY = MathHelper.floor(source.y - power - 1); + int maxY = MathHelper.floor(source.y + power + 1); + int minZ = MathHelper.floor(source.z - power - 1); + int maxZ = MathHelper.floor(source.z + power + 1); for (Entity entity : world.getOtherEntities(null, new Box(minX, minY, minZ, maxX, maxY, maxZ))) { if (!entity.isImmuneToExplosion(this) && ProtectionsProvider.canDamageEntity(entity, damageSource)) { double distance = Math.sqrt(entity.squaredDistanceTo(source)) / power; if (distance <= 1) { - double dX = entity.getX() - x; - double dY = (entity instanceof TntEntity ? entity.getY() : entity.getEyeY()) - y; - double dZ = entity.getZ() - z; + double dX = entity.getX() - source.x; + double dY = (entity instanceof TntEntity ? entity.getY() : entity.getEyeY()) - source.y; + double dZ = entity.getZ() - source.z; double product = Math.sqrt(dX * dX + dY * dY + dZ * dZ); if (product != 0) { dX /= product; @@ -122,20 +122,20 @@ public void collectBlocksAndDamageEntities() { @Override public void affectWorld(boolean particles) { - world.playSound(null, x, y, z, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4, (1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F); + Vec3d source = getPosition(); + world.playSound(null, source.x, source.y, source.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) { if (getPower() >= 2 && destroy) { - world.addParticle(ParticleTypes.EXPLOSION_EMITTER, x, y, z, 1, 0, 0); + world.addParticle(ParticleTypes.EXPLOSION_EMITTER, source.x, source.y, source.z, 1, 0, 0); } else { - world.addParticle(ParticleTypes.EXPLOSION, x, y, z, 1, 0, 0); + world.addParticle(ParticleTypes.EXPLOSION, source.x, source.y, source.z, 1, 0, 0); } } if (destroy) { - Util.shuffle(affectedBlocks, world.random); - Vec3d source = new Vec3d(x, y, z); + Util.shuffle(getAffectedBlocks(), world.random); ObjectArrayList> destroyedBlocks = new ObjectArrayList<>(); - for (BlockPos pos : affectedBlocks) { + for (BlockPos pos : getAffectedBlocks()) { if (canPlace(pos) && canExplode(pos)) { BlockState state = world.getBlockState(pos); if (!state.isAir()) { @@ -163,7 +163,7 @@ public void affectWorld(boolean particles) { BlockState adjacentBlockState = world.getBlockState(mutable.set(pos, direction)); FluidState fluidState = world.getFluidState(mutable.set(pos, direction)); Optional optional = behavior.getBlastResistance(this, world, mutable.set(pos, direction), adjacentBlockState, fluidState); - if (optional.isPresent() && optional.get() < 1200 && !affectedBlocks.contains(mutable.set(pos, direction))) { + if (optional.isPresent() && optional.get() < 1200 && !getAffectedBlocks().contains(mutable.set(pos, direction))) { world.setBlockState(mutable.set(pos, direction), BlastBlocks.FOLLY_RED_PAINT.getDefaultState()); } } diff --git a/src/main/java/ladysnake/blast/common/world/CustomExplosion.java b/src/main/java/ladysnake/blast/common/world/CustomExplosion.java index d6aca86..2592e24 100644 --- a/src/main/java/ladysnake/blast/common/world/CustomExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/CustomExplosion.java @@ -38,27 +38,28 @@ public CustomExplosion(World world, Entity entity, double x, double y, double z, @Override public void affectWorld(boolean particles) { - world.playSound(null, x, y, z, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4, (1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F); + Vec3d source = getPosition(); + world.playSound(null, source.x, source.y, source.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) { if (getPower() >= 2 && destroy) { - world.addParticle(ParticleTypes.EXPLOSION_EMITTER, x, y, z, 1, 0, 0); + world.addParticle(ParticleTypes.EXPLOSION_EMITTER, source.x, source.y, source.z, 1, 0, 0); } else { - world.addParticle(ParticleTypes.EXPLOSION, x, y, z, 1, 0, 0); + world.addParticle(ParticleTypes.EXPLOSION, source.x, source.y, source.z, 1, 0, 0); } } if (destroy) { ObjectArrayList> destroyedBlocks = new ObjectArrayList<>(); - for (BlockPos pos : affectedBlocks) { + for (BlockPos pos : getAffectedBlocks()) { if (canExplode(pos)) { BlockState state = world.getBlockState(pos); if (particles) { double rX = pos.getX() + world.random.nextFloat(); double rY = pos.getY() + world.random.nextFloat(); double rZ = pos.getZ() + world.random.nextFloat(); - double dX = rX - x; - double dY = rY - y; - double dZ = rZ - z; + double dX = rX - source.x; + double dY = rY - source.y; + double dZ = rZ - source.z; double product = Math.sqrt(dX * dX + dY * dY + dZ * dZ); dX /= product; dY /= product; @@ -69,10 +70,10 @@ public void affectWorld(boolean particles) { dY *= multiplier; dZ *= multiplier; if (state.getFluidState().isEmpty()) { - world.addParticle(ParticleTypes.POOF, (rX + x) / 2, (rY + y) / 2, (rZ + z) / 2, dX, dY, dZ); + world.addParticle(ParticleTypes.POOF, (rX + source.x) / 2, (rY + source.y) / 2, (rZ + source.z) / 2, dX, dY, dZ); world.addParticle(ParticleTypes.SMOKE, rX, rY, rZ, dX, dY, dZ); } else { - world.addParticle(ParticleTypes.BUBBLE, (rX + x) / 2, (rY + y) / 2, (rZ + z) / 2, dX, dY, dZ); + world.addParticle(ParticleTypes.BUBBLE, (rX + source.x) / 2, (rY + source.y) / 2, (rZ + source.z) / 2, dX, dY, dZ); world.addParticle(ParticleTypes.BUBBLE_POP, rX, rY, rZ, dX, dY, dZ); } } @@ -128,7 +129,7 @@ public void affectWorld(boolean particles) { destroyedBlocks.forEach(pair -> Block.dropStack(world, pair.getSecond(), pair.getFirst())); } if (effect == BlockBreakEffect.FIERY) { - for (BlockPos pos : affectedBlocks) { + for (BlockPos pos : getAffectedBlocks()) { if (!world.isClient && canPlace(pos)) { if (random.nextInt(3) == 0 && world.getBlockState(pos).isAir() && world.getBlockState(pos.down()).isOpaqueFullCube(world, pos.down())) { world.setBlockState(pos, AbstractFireBlock.getState(world, pos)); diff --git a/src/main/java/ladysnake/blast/common/world/EnderExplosion.java b/src/main/java/ladysnake/blast/common/world/EnderExplosion.java index 367ac19..2c1516a 100644 --- a/src/main/java/ladysnake/blast/common/world/EnderExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/EnderExplosion.java @@ -32,10 +32,11 @@ 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)); - world.playSound(null, x, y, z, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 4, (1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.9F); + Vec3d source = getPosition(); + BlockPos blockSource = BlockPos.ofFloored(source); + world.playSound(null, source.x, source.y, source.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) { + for (BlockPos pos : getAffectedBlocks()) { if (canExplode(pos)) { BlockState state = world.getBlockState(pos); if (!state.isAir()) { @@ -53,7 +54,7 @@ public void affectWorld(boolean particles) { if (state.getBlock().shouldDropItemsOnExplosion(this)) { ItemStack stack = Items.NETHERITE_PICKAXE.getDefaultStack(); stack.addEnchantment(world.getRegistryManager().get(RegistryKeys.ENCHANTMENT).entryOf(Enchantments.SILK_TOUCH), 1); - state.getDroppedStacks(getBuilder(serverWorld, pos, stack, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null)).forEach(droppedStack -> tryMergeStack(destroyedBlocks, droppedStack, source)); + state.getDroppedStacks(getBuilder(serverWorld, pos, stack, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null)).forEach(droppedStack -> tryMergeStack(destroyedBlocks, droppedStack, blockSource)); } world.setBlockState(pos, Blocks.AIR.getDefaultState()); } diff --git a/src/main/java/ladysnake/blast/common/world/EntityExplosion.java b/src/main/java/ladysnake/blast/common/world/EntityExplosion.java index 4fe8e46..a1b8d21 100644 --- a/src/main/java/ladysnake/blast/common/world/EntityExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/EntityExplosion.java @@ -26,7 +26,7 @@ public void affectWorld(boolean particles) { if (entity instanceof ProjectileEntity projectileEntity) { projectileEntity.setOwner(this.entity); } - entity.setPosition(this.x, this.y, this.z); + entity.setPosition(getPosition()); entity.setVelocity(random.nextGaussian() * velocity, random.nextGaussian() * velocity, random.nextGaussian() * velocity); world.spawnEntity(entity); } diff --git a/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java b/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java index 9ea0480..4eb1062 100644 --- a/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java +++ b/src/main/java/ladysnake/blast/common/world/KnockbackExplosion.java @@ -16,19 +16,19 @@ public KnockbackExplosion(World world, Entity entity, double x, double y, double @Override public void affectWorld(boolean particles) { - Vec3d source = new Vec3d(x, y, z); + Vec3d source = getPosition(); 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); + world.addParticle(ParticleTypes.SNEEZE, source.x, source.y, source.z, this.random.nextGaussian() / 5, this.random.nextGaussian() / 5, this.random.nextGaussian() / 5); } } for (Entity entity : affectedEntities) { if (ProtectionsProvider.canInteractEntity(entity, damageSource)) { double distance = Math.sqrt(entity.squaredDistanceTo(source)) / (getPower() * 2); if (distance <= 1.0D) { - double dX = entity.getX() - this.x; - double dY = entity.getEyeY() - this.y; - double dZ = entity.getZ() - this.z; + double dX = entity.getX() - source.x; + double dY = entity.getEyeY() - source.y; + double dZ = entity.getZ() - source.z; double product = Math.sqrt(dX * dX + dY * dY + dZ * dZ); if (product != 0) { dX /= product; diff --git a/src/main/resources/blast.accesswidener b/src/main/resources/blast.accesswidener index db82fd9..6470b76 100644 --- a/src/main/resources/blast.accesswidener +++ b/src/main/resources/blast.accesswidener @@ -4,10 +4,6 @@ accessible method net/minecraft/entity/projectile/FireworkRocketEntity explodeAn accessible field net/minecraft/world/explosion/Explosion destructionType Lnet/minecraft/world/explosion/Explosion$DestructionType; accessible field net/minecraft/world/explosion/Explosion random Lnet/minecraft/util/math/random/Random; accessible field net/minecraft/world/explosion/Explosion world Lnet/minecraft/world/World; -accessible field net/minecraft/world/explosion/Explosion x D -accessible field net/minecraft/world/explosion/Explosion y D -accessible field net/minecraft/world/explosion/Explosion z D accessible field net/minecraft/world/explosion/Explosion entity Lnet/minecraft/entity/Entity; accessible field net/minecraft/world/explosion/Explosion damageSource Lnet/minecraft/entity/damage/DamageSource; accessible field net/minecraft/world/explosion/Explosion behavior Lnet/minecraft/world/explosion/ExplosionBehavior; -accessible field net/minecraft/world/explosion/Explosion affectedBlocks Lit/unimi/dsi/fastutil/objects/ObjectArrayList;