Skip to content

Commit

Permalink
remove unneeded access wideners
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Oct 19, 2024
1 parent 9a8cca2 commit 4840728
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockPos> set = new HashSet<>();
BlockPos.Mutable mutable = new BlockPos.Mutable();
for (int i = 0; i < 16; i++) {
Expand All @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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<Pair<ItemStack, BlockPos>> destroyedBlocks = new ObjectArrayList<>();
for (BlockPos pos : affectedBlocks) {
for (BlockPos pos : getAffectedBlocks()) {
if (canPlace(pos) && canExplode(pos)) {
BlockState state = world.getBlockState(pos);
if (!state.isAir()) {
Expand Down Expand Up @@ -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<Float> 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());
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/ladysnake/blast/common/world/CustomExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<ItemStack, BlockPos>> 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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<ItemStack, BlockPos>> destroyedBlocks = new ObjectArrayList<>();
for (BlockPos pos : affectedBlocks) {
for (BlockPos pos : getAffectedBlocks()) {
if (canExplode(pos)) {
BlockState state = world.getBlockState(pos);
if (!state.isAir()) {
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/blast.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 4840728

Please sign in to comment.