Skip to content

Commit 8274721

Browse files
committed
fixed bounding box bug
1 parent c8f0986 commit 8274721

4 files changed

Lines changed: 21 additions & 25 deletions

File tree

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/AbstractThrusterBlockEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ public boolean isController() {
9090

9191
//We need to cache the bounding box to avoid recalculating it every tick
9292
@OnlyIn(Dist.CLIENT)
93+
//Used for tracking the state of the thruster so we dont have to recalculate the bounding box every time
9394
protected int boundingBoxHash;
9495
@OnlyIn(Dist.CLIENT)
95-
public AABB boundingBox = MeshedThrusterFlameUtils.NULL_AABB;
96+
public AABB boundingBox = getSingleRenderBox();
9697
@OnlyIn(Dist.CLIENT)
9798
protected AABB multiblockBoundingBox;
9899

@@ -132,7 +133,6 @@ public AABB getRenderBoundingBox() {
132133
//Inflate and cache the bounding box
133134
AABB inflated = MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, getSingleRenderBox());
134135
if (inflated != null) { //Update the bounding box
135-
// System.out.println("Inflated bounding box: " + inflated);
136136
boundingBox = inflated;
137137
multiblockBoundingBox = null;
138138
}

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/MeshedThrusterFlameUtils.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,7 @@ private static float random01(int seed) {
169169
return (float) ((z >>> 40) * (1.0 / (1L << 24)));
170170
}
171171

172-
private static int hash(float x, float y, float z) {
173-
// Start with a prime number
174-
int result = 1;
175-
176-
// Combine each float
177-
result = 31 * result + Float.floatToIntBits(x);
178-
result = 31 * result + Float.floatToIntBits(y);
179-
result = 31 * result + Float.floatToIntBits(z);
180-
return result;
181-
}
182-
183-
private static int hash(float x, float y) {
184-
// Start with a prime number
185-
int result = 1;
186172

187-
// Combine each float
188-
result = 31 * result + Float.floatToIntBits(x);
189-
result = 31 * result + Float.floatToIntBits(y);
190-
return result;
191-
}
192173

193174
private static float getRenderBoxLength(AbstractThrusterBlockEntity be) {
194175
return (float) (Math.ceil(be.interpolatedPower.getValue() * 10) / 10 * RENDER_BOX_FLAME_LENGTH);
@@ -203,7 +184,12 @@ private static float getRenderBoxLength(AbstractThrusterBlockEntity be) {
203184
*/
204185
public static AABB inflateRenderBoundingBox(AbstractThrusterBlockEntity be, AABB box) {
205186
float length = getRenderBoxLength(be);
206-
int hash = Float.floatToRawIntBits(length);
187+
188+
//Hash the state of the thruster
189+
int hash = 1;
190+
hash = 31 * hash + Float.floatToRawIntBits(length);
191+
hash = 31 * hash + box.hashCode();
192+
207193

208194
if (be.boundingBoxHash != hash) {
209195
be.boundingBoxHash = hash;
@@ -235,8 +221,15 @@ public static AABB inflateVectorRenderBoundingBox(VectorThrusterBlockEntity be,
235221
float xInflate = be.getInterpolatedVectorX(1) * 3.5f;
236222
float yInflate = be.getInterpolatedVectorY(1) * 3.5f;
237223
float length = Math.max(0, getRenderBoxLength(be) - Math.max(Math.abs(xInflate), Math.abs(yInflate)) * 0.8f);
238-
int hash = hash(xInflate, yInflate, length);
239224

225+
//Hash the state of the thruster
226+
int hash = 1;
227+
hash = 31 * hash + Float.floatToRawIntBits(xInflate);
228+
hash = 31 * hash + Float.floatToRawIntBits(yInflate);
229+
hash = 31 * hash + Float.floatToRawIntBits(length);
230+
hash = 31 * hash + box.hashCode();
231+
232+
//Compare the current vs previous state of the thruster
240233
if (be.boundingBoxHash != hash) {
241234
be.boundingBoxHash = hash;
242235
Vec3 center = box.getCenter();

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/ion_thruster/IonThrusterBlockEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.propulsionteam.propulsionsimulated.content.thruster.ion_thruster;
22

3+
import dev.propulsionteam.propulsionsimulated.content.thruster.MeshedThrusterFlameUtils;
34
import dev.propulsionteam.propulsionsimulated.content.thruster.ThrusterDamager;
45

56
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
@@ -25,6 +26,7 @@
2526
import net.minecraft.world.item.ItemStack;
2627
import net.minecraft.world.level.block.state.BlockState;
2728
import net.minecraft.world.level.block.entity.BlockEntityType;
29+
import net.minecraft.world.phys.AABB;
2830
import net.neoforged.neoforge.energy.IEnergyStorage;
2931
import net.neoforged.neoforge.fluids.FluidStack;
3032
import net.neoforged.neoforge.fluids.capability.IFluidHandler;

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/thruster/ThrusterRenderer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ protected void renderSafe(ThrusterBlockEntity be, float partialTick, PoseStack m
4545
ms.scale(w, w, w);
4646
mb.light(light).overlay(overlay).renderInto(ms, vb);
4747
ms.popPose();
48-
MeshedThrusterFlameUtils.renderMultiblockFlame(be, partialTick, ms, buffer, w);
48+
if (MeshedThrusterFlameUtils.isSpritePlume(be))
49+
MeshedThrusterFlameUtils.renderMultiblockFlame(be, partialTick, ms, buffer, w);
4950
}
50-
} else {
51+
} else if (MeshedThrusterFlameUtils.isSpritePlume(be)) {
5152
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer);
5253
}
5354
}

0 commit comments

Comments
 (0)