Skip to content

Commit 6911379

Browse files
committed
Change explosion calculation to be ray-based
1 parent 217e11c commit 6911379

1 file changed

Lines changed: 25 additions & 43 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/mixin/explosion/ExplosionMixin.java

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -102,53 +102,35 @@ public class ExplosionMixin {
102102

103103
for (final SubLevel subLevel : subLevels) {
104104
final Pose3d pose = subLevel.logicalPose();
105+
final Vec3 localRayPosition = pose.transformPositionInverse(new Vec3(d4, d6, d8));
106+
final Vec3 localExplosionPosition = pose.transformPositionInverse(new Vec3(this.x, this.y, this.z));
105107

106-
final BoundingBox3d localBounds = new BoundingBox3d();
107-
globalBounds.transformInverse(pose, localBounds);
108+
blockpos = BlockPos.containing(localRayPosition);
109+
blockstate = this.level.getBlockState(blockpos);
110+
fluidstate = this.level.getFluidState(blockpos);
108111

109-
final BoundingBox3i blockBounds = new BoundingBox3i(
110-
Mth.floor(localBounds.minX()),
111-
Mth.floor(localBounds.minY()),
112-
Mth.floor(localBounds.minZ()),
113-
Mth.floor(localBounds.maxX()),
114-
Mth.floor(localBounds.maxY()),
115-
Mth.floor(localBounds.maxZ())
116-
);
112+
final boolean canExplodeBefore = f > 0.0;
117113

118-
final Vec3 localExplosionPosition = pose.transformPositionInverse(new Vec3(this.x, this.y, this.z));
114+
final Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(self, this.level, blockpos, blockstate, fluidstate);
115+
if (optional.isPresent()) {
116+
f -= (optional.get() + 0.3F) * 0.3F;
117+
}
118+
119+
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(self, this.level, blockpos, blockstate, f)) {
120+
set.add(blockpos);
121+
}
122+
123+
final boolean wind = this.source instanceof AbstractWindCharge && !blockstate.isAir();
124+
if (canExplodeBefore && (f < 0.0f || wind) && explodedSet.get().add(blockpos)) {
125+
explodedSet.get().add(blockpos);
126+
127+
if (subLevel instanceof final ServerSubLevel serverSubLevel) {
128+
final SubLevelPhysicsSystem physicsSystem = ((ServerSubLevelContainer) container).physicsSystem();
129+
final RigidBodyHandle handle = physicsSystem.getPhysicsHandle(serverSubLevel);
119130

120-
for (int x = blockBounds.minX(); x <= blockBounds.maxX(); x++) {
121-
for (int z = blockBounds.minZ(); z <= blockBounds.maxZ(); z++) {
122-
for (int y = blockBounds.minY(); y <= blockBounds.maxY(); y++) {
123-
blockpos = new BlockPos(x, y, z);
124-
blockstate = this.level.getBlockState(blockpos);
125-
fluidstate = this.level.getFluidState(blockpos);
126-
127-
final boolean canExplodeBefore = f > 0.0;
128-
129-
final Optional<Float> optional = this.damageCalculator.getBlockExplosionResistance(self, this.level, blockpos, blockstate, fluidstate);
130-
if (optional.isPresent()) {
131-
f -= (optional.get() + 0.3F) * 0.3F;
132-
}
133-
134-
if (f > 0.0F && this.damageCalculator.shouldBlockExplode(self, this.level, blockpos, blockstate, f)) {
135-
set.add(blockpos);
136-
}
137-
138-
final boolean wind = this.source instanceof AbstractWindCharge && !blockstate.isAir();
139-
if (canExplodeBefore && (f < 0.0f || wind) && explodedSet.get().add(blockpos)) {
140-
explodedSet.get().add(blockpos);
141-
142-
if (subLevel instanceof final ServerSubLevel serverSubLevel) {
143-
final SubLevelPhysicsSystem physicsSystem = ((ServerSubLevelContainer) container).physicsSystem();
144-
final RigidBodyHandle handle = physicsSystem.getPhysicsHandle(serverSubLevel);
145-
146-
final Vec3 pos = blockpos.getCenter();
147-
final Vec3 force = pos.subtract(localExplosionPosition).normalize().scale(5.0);
148-
handle.applyImpulseAtPoint(pos, force);
149-
}
150-
}
151-
}
131+
final Vec3 pos = blockpos.getCenter();
132+
final Vec3 force = pos.subtract(localExplosionPosition).normalize().scale(5.0);
133+
handle.applyImpulseAtPoint(pos, force);
152134
}
153135
}
154136
}

0 commit comments

Comments
 (0)