From 0ad6db4bf75211b36bb70c0ec7d14edc62fbe411 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 23:06:41 -0800 Subject: [PATCH] cache KTEs' renderBoundingBox --- .../contraptions/base/KineticTileEntity.java | 17 +++++++++++++++- .../PortableStorageInterfaceTileEntity.java | 6 +++++- .../crusher/CrushingWheelTileEntity.java | 2 +- .../deployer/DeployerTileEntity.java | 4 ++-- .../flywheel/FlywheelTileEntity.java | 4 ++-- .../flywheel/engine/EngineTileEntity.java | 9 ++++++++- .../mixer/MechanicalMixerTileEntity.java | 2 +- .../press/MechanicalPressTileEntity.java | 2 +- .../pulley/PulleyTileEntity.java | 4 ++-- .../waterwheel/WaterWheelTileEntity.java | 2 +- .../fluids/actors/SpoutTileEntity.java | 9 ++++++++- .../fluids/tank/FluidTankTileEntity.java | 16 +++++++++++---- .../relays/belt/BeltTileEntity.java | 20 +++++++++---------- .../elementary/SimpleKineticTileEntity.java | 2 +- .../block/mechanicalArm/ArmTileEntity.java | 4 ++-- 15 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 044cc2520..c439ace0f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -26,10 +26,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import javax.annotation.Nullable; @@ -464,7 +466,7 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override public double getMaxRenderDistanceSquared() { - return 16384.0D; // TODO: make this a config option + return super.getMaxRenderDistanceSquared(); } @Override @@ -492,4 +494,17 @@ public abstract class KineticTileEntity extends SmartTileEntity public void onChunkLightUpdate() { CreateClient.kineticRenderer.onLightUpdate(this); } + + protected AxisAlignedBB cachedBoundingBox; + @OnlyIn(Dist.CLIENT) + public AxisAlignedBB getRenderBoundingBox() { + if (cachedBoundingBox == null) { + cachedBoundingBox = makeRenderBoundingBox(); + } + return cachedBoundingBox; + } + + protected AxisAlignedBB makeRenderBoundingBox() { + return super.getRenderBoundingBox(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java index de4043458..2972a1627 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java @@ -100,10 +100,14 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity return powered; } + protected AxisAlignedBB cachedBoundingBox; @Override @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(2); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().grow(2); + } + return cachedBoundingBox; } public boolean isTransferring() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java index d14531a6c..8d94992d5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java @@ -36,7 +36,7 @@ public class CrushingWheelTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index 0dfd92f12..e311d5f1e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -341,8 +341,8 @@ public class DeployerTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(3); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(3); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java index b55c81d63..830081dfb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java @@ -47,8 +47,8 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(2); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(2); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index a0869af09..6a3988caa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -14,6 +14,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class EngineTileEntity extends SmartTileEntity { @@ -34,9 +36,14 @@ public class EngineTileEntity extends SmartTileEntity { return true; } + protected AxisAlignedBB cachedBoundingBox; @Override + @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(1.5f); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().grow(1.5f); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java index b6037c0c7..6073f366e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java @@ -80,7 +80,7 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).expand(0, -1.5, 0); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java index 3d320743a..91d4359fb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java @@ -102,7 +102,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).expand(0, -1.5, 0) .expand(0, 1, 0); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index a416edadc..cfac43101 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -32,8 +32,8 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().expand(0, -offset, 0); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().expand(0, -offset, 0); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java index 882f2a15e..6b0fc0df9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java @@ -36,7 +36,7 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java index 564ae6a33..584204b4a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java @@ -29,6 +29,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; @@ -49,9 +51,14 @@ public class SpoutTileEntity extends SmartTileEntity { processingTicks = -1; } + protected AxisAlignedBB cachedBoundingBox; @Override + @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().expand(0, -2, 0); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().expand(0, -2, 0); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java index aa487a29b..bfa94720a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java @@ -104,7 +104,10 @@ public class FluidTankTileEntity extends SmartTileEntity { } public boolean isController() { - return controller == null || controller.equals(pos); + return controller == null || + pos.getX() == controller.getX() && + pos.getY() == controller.getY() && + pos.getZ() == controller.getZ(); } @Override @@ -281,12 +284,17 @@ public class FluidTankTileEntity extends SmartTileEntity { return isController() ? pos : controller; } + private AxisAlignedBB cachedBoundingBox; @Override @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - if (isController()) - return super.getRenderBoundingBox().expand(width - 1, height - 1, width - 1); - return super.getRenderBoundingBox(); + if (cachedBoundingBox == null) { + if (isController()) + cachedBoundingBox = super.getRenderBoundingBox().expand(width - 1, height - 1, width - 1); + else + cachedBoundingBox = super.getRenderBoundingBox(); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 34c972ae5..26309905f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -137,17 +137,12 @@ public class BeltTileEntity extends KineticTileEntity { return super.calculateStressApplied(); } - private AxisAlignedBB cachedBoundingBox; @Override - public AxisAlignedBB getRenderBoundingBox() { - if (cachedBoundingBox == null) { - if (!isController()) - cachedBoundingBox = super.getRenderBoundingBox(); - else - cachedBoundingBox = super.getRenderBoundingBox().grow(beltLength + 1); - } - - return cachedBoundingBox; + public AxisAlignedBB makeRenderBoundingBox() { + if (!isController()) + return super.makeRenderBoundingBox(); + else + return super.makeRenderBoundingBox().grow(beltLength + 1); } protected void initializeItemHandler() { @@ -275,7 +270,10 @@ public class BeltTileEntity extends KineticTileEntity { } public boolean isController() { - return pos.equals(controller); + return controller != null && + pos.getX() == controller.getX() && + pos.getY() == controller.getY() && + pos.getZ() == controller.getZ(); } public float getBeltMovementSpeed() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java index 864b659f3..29c997c6b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java @@ -24,7 +24,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index c4370c2b4..767639361 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -139,8 +139,8 @@ public class ArmTileEntity extends KineticTileEntity { @Override @OnlyIn(Dist.CLIENT) - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(3); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(3); } private boolean checkForMusicAmong(List list) {