Skip to content

Commit 124d710

Browse files
committed
cache multiblock render aabb
1 parent f079cc5 commit 124d710

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/java/mekanism/client/render/tileentity/MultiblockTileEntityRenderer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.blaze3d.vertex.PoseStack;
44
import mekanism.api.annotations.NothingNullByDefault;
5+
import mekanism.common.lib.math.voxel.VoxelCuboid;
56
import mekanism.common.lib.multiblock.MultiblockData;
67
import mekanism.common.tile.prefab.TileEntityMultiblock;
78
import net.minecraft.client.renderer.MultiBufferSource;
@@ -46,11 +47,11 @@ protected boolean shouldRender(TILE tile, MULTIBLOCK multiblock, Vec3 camera) {
4647
public AABB getRenderBoundingBox(TILE tile) {
4748
if (tile.isMaster()) {
4849
MULTIBLOCK multiblock = tile.getMultiblock();
49-
if (multiblock.isFormed() && multiblock.getBounds() != null) {
50-
//TODO: Eventually we may want to look into caching this
50+
VoxelCuboid bounds = multiblock.getBounds();
51+
if (multiblock.isFormed() && bounds != null) {
5152
//Note: We do basically the full dimensions as it still is a lot smaller than always rendering it, and makes sure no matter
5253
// how the specific multiblock wants to render, that it is being viewed
53-
return AABB.encapsulatingFullBlocks(multiblock.getMinPos(), multiblock.getMaxPos());
54+
return bounds.asAABB();
5455
}
5556
}
5657
return super.getRenderBoundingBox(tile);

src/main/java/mekanism/common/lib/math/voxel/VoxelCuboid.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
import mekanism.common.lib.multiblock.Structure.Axis;
44
import net.minecraft.core.BlockPos;
55
import net.minecraft.core.Direction;
6+
import net.minecraft.world.phys.AABB;
67

78
public class VoxelCuboid implements IShape {
89

910
private BlockPos minPos;
1011
private BlockPos maxPos;
12+
private AABB asAABB;
1113

1214
public VoxelCuboid(BlockPos minPos, BlockPos maxPos) {
1315
this.minPos = minPos;
1416
this.maxPos = maxPos;
17+
this.asAABB = AABB.encapsulatingFullBlocks(minPos, maxPos);
1518
}
1619

1720
public VoxelCuboid(int length, int height, int width) {
@@ -40,10 +43,12 @@ public BlockPos getMaxPos() {
4043

4144
public void setMinPos(BlockPos minPos) {
4245
this.minPos = minPos;
46+
this.asAABB = AABB.encapsulatingFullBlocks(minPos, maxPos);
4347
}
4448

4549
public void setMaxPos(BlockPos maxPos) {
4650
this.maxPos = maxPos;
51+
this.asAABB = AABB.encapsulatingFullBlocks(minPos, maxPos);
4752
}
4853

4954
public BlockPos getCenter() {
@@ -163,6 +168,10 @@ public String toString() {
163168
return "Cuboid(start=" + minPos + ", bounds=(" + length() + "," + height() + "," + width() + "))";
164169
}
165170

171+
public AABB asAABB() {
172+
return asAABB;
173+
}
174+
166175
public enum WallRelative {
167176
SIDE,
168177
EDGE,

0 commit comments

Comments
 (0)