Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix blockPosition checks for reactions #831

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/be/minelabs/item/reaction/CorrosiveReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ public CorrosiveReaction(int radius) {
}

@Override
protected void react(World world, Vec3d pos) {
Utils.applyBlocksRadiusTraced(world, pos, this.radius, block -> {
BlockState blockState = world.getBlockState(BlockPos.ofFloored(pos));
protected void react(World world, Vec3d sourcePos) {
Utils.applyBlocksRadiusTraced(world, sourcePos, this.radius, pos -> {
BlockState blockState = world.getBlockState(pos);
if (blockState.getBlock() == net.minecraft.block.Blocks.WATER)
world.addParticle(ParticleTypes.CLOUD, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0);
else
if(canReact(world.getBlockState(block))) {
if(canReact(world.getBlockState(pos))) {
// Calculate the distance between pos and block
double distance = pos.distanceTo(Vec3d.ofCenter(block));
double distance = sourcePos.distanceTo(Vec3d.ofCenter(pos));
// Create a new CorrosiveEntity at the given blockpos
CorrosiveEntity entity = CorrosiveEntity.create(world, block, distance);
CorrosiveEntity entity = CorrosiveEntity.create(world, pos, distance);
// Spawn the entity
world.spawnEntity(entity);
}
});
Utils.applyEntitiesRadiusTraced(world, pos, radius, this::react);
Utils.applyEntitiesRadiusTraced(world, sourcePos, radius, this::react);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/minelabs/item/reaction/DissolveReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public class DissolveReaction extends Reaction {

@Override
protected void react(World world, Vec3d pos) {
protected void react(World world, Vec3d sourcePos) {
for (int i = 0; i < 10; i++) {
world.addParticle(ParticleTypes.CLOUD, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0);
world.addParticle(ParticleTypes.CLOUD, sourcePos.getX(), sourcePos.getY(), sourcePos.getZ(), 0, 0, 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public ExplosiveReaction(int power, boolean flammable, boolean pyrophoric) {
}

@Override
protected void react(World world, Vec3d pos) {
protected void react(World world, Vec3d sourcePos) {
GameRules gameRules = world.getGameRules();
if (!gameRules.getBoolean(GameRules.DO_MOB_GRIEFING))
return;
if (this.pyrophoric || Utils.isFlameNearby(world, pos, power))
world.createExplosion(null, pos.x, pos.y, pos.z,
if (this.pyrophoric || Utils.isFlameNearby(world, sourcePos, power))
world.createExplosion(null, sourcePos.x, sourcePos.y, sourcePos.z,
power, flammable && gameRules.getBoolean(GameRules.DO_FIRE_TICK), World.ExplosionSourceType.BLOCK);

}
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/be/minelabs/item/reaction/ExtinguishReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ public ExtinguishReaction(int radius) {
}

@Override
protected void react(World world, Vec3d pos) {
Utils.applyBlocksRadiusTraced(world, pos, this.radius, blockPosition -> {
BlockState block = world.getBlockState(blockPosition);
BlockPos blockPos = BlockPos.ofFloored(pos);
protected void react(World world, Vec3d sourcePos) {
Utils.applyBlocksRadiusTraced(world, sourcePos, this.radius, pos -> {
BlockState block = world.getBlockState(pos);
if (block.isIn(BlockTags.FIRE)) {
world.removeBlock(blockPos, false);
world.removeBlock(pos, false);
} else if (AbstractCandleBlock.isLitCandle(block)) {
AbstractCandleBlock.extinguish(null, block, world, blockPos);
AbstractCandleBlock.extinguish(null, block, world, pos);
} else if (CampfireBlock.isLitCampfire(block)) {
world.syncWorldEvent(null, 1009, blockPos, 0);
CampfireBlock.extinguish(null, world, blockPos, block);
world.setBlockState(blockPos, block.with(CampfireBlock.LIT, false));
world.syncWorldEvent(null, 1009, pos, 0);
CampfireBlock.extinguish(null, world, pos, block);
world.setBlockState(pos, block.with(CampfireBlock.LIT, false));
}
});

Utils.applyEntitiesRadiusTraced(world, pos, this.radius, this::react);
Utils.applyEntitiesRadiusTraced(world, sourcePos, this.radius, this::react);
}

@Override
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/be/minelabs/item/reaction/FlammableReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ public FlammableReaction(int duration, int radius, boolean pyrophoric) {
}

@Override
protected void react(World world, Vec3d pos) {
// Radius halved because Ine said so
Utils.applyBlocksRadiusTraced(world, pos, radius / 2, block -> {
protected void react(World world, Vec3d sourcePos) {
boolean doFire = this.pyrophoric
|| Utils.isFlameNearby(world, sourcePos, radius)
|| world.getBiome(BlockPos.ofFloored(sourcePos.x, sourcePos.y, sourcePos.z)).isIn(Tags.Biomes.FLAMMABLE_BIOMES);

Utils.applyBlocksRadiusTraced(world, sourcePos, radius / 2, pos -> {
if(!world.getGameRules().getBoolean(GameRules.DO_FIRE_TICK))
return;
if (world.getBlockState(block).getBlock() != Blocks.AIR)
if (!world.getBlockState(pos).isOf(Blocks.AIR))
return;
if (this.pyrophoric || Utils.isFlameNearby(world, block.toCenterPos(), 3)
|| world.getBiome(BlockPos.ofFloored(pos.x, pos.y, pos.z)).isIn(Tags.Biomes.FLAMMABLE_BIOMES))
world.setBlockState(block, Blocks.FIRE.getDefaultState().with(FireBlock.AGE, 1));
if (doFire)
world.setBlockState(pos, Blocks.FIRE.getDefaultState().with(FireBlock.AGE, 1));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public PoisonousReaction(int radius, int duration, int amplifier) {
}

@Override
protected void react(World world, Vec3d pos) {
Utils.applyEntitiesRadiusTraced(world, pos, radius, this::react);
protected void react(World world, Vec3d sourcePos) {
Utils.applyEntitiesRadiusTraced(world, sourcePos, radius, this::react);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/be/minelabs/item/reaction/Reaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else if (hitResult instanceof EntityHitResult entityHitResult)
react(world, entityHitResult.getEntity().getPos());
}

protected abstract void react(World world, Vec3d position);
protected abstract void react(World world, Vec3d sourcePos);

public abstract void react(LivingEntity entity);

Expand Down