From 2cdbdfa2182cf6b979b4395e9212305098b324ee Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 5 Jan 2022 11:12:26 -0800 Subject: [PATCH] Towards client-only flywheel - Fix nullpointer with belt lighter - Remove references to GridAlignedBB and ImmutableBox in Contraption --- .../structureMovement/Contraption.java | 24 ++++++++++--------- .../relays/belt/BeltRenderer.java | 7 +++--- .../relays/belt/BeltTileEntity.java | 21 ++++++++++++++-- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 312afd33c..ca52109ea 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -25,8 +25,6 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.util.box.GridAlignedBB; -import com.jozufozu.flywheel.util.box.ImmutableBox; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllInteractionBehaviours; import com.simibubi.create.AllMovementBehaviours; @@ -1178,21 +1176,25 @@ public abstract class Contraption { int radius = (int) (Math.ceil(Math.sqrt(getRadius(blocks, axis)))); - GridAlignedBB betterBounds = GridAlignedBB.ofRadius(radius); + int maxX = radius + 2; + int maxY = radius + 2; + int maxZ = radius + 2; + int minX = -radius - 1; + int minY = -radius - 1; + int minZ = -radius - 1; - ImmutableBox contraptionBounds = GridAlignedBB.from(bounds); if (axis == Direction.Axis.X) { - betterBounds.setMaxX(contraptionBounds.getMaxX()); - betterBounds.setMinX(contraptionBounds.getMinX()); + maxX = (int) bounds.maxX; + minX = (int) bounds.minX; } else if (axis == Direction.Axis.Y) { - betterBounds.setMaxY(contraptionBounds.getMaxY()); - betterBounds.setMinY(contraptionBounds.getMinY()); + maxY = (int) bounds.maxY; + minY = (int) bounds.minY; } else if (axis == Direction.Axis.Z) { - betterBounds.setMaxZ(contraptionBounds.getMaxZ()); - betterBounds.setMinZ(contraptionBounds.getMinZ()); + maxZ = (int) bounds.maxZ; + minZ = (int) bounds.minZ; } - bounds = betterBounds.toAABB(); + bounds = new AABB(minX, minY, minZ, maxX, maxY, maxZ); } public void addExtraInventories(Entity entity) {} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 6a9aa20e6..b27ed9d8b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -25,7 +25,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; @@ -308,11 +307,11 @@ public class BeltRenderer extends SafeTileEntityRenderer { } protected int getPackedLight(BeltTileEntity controller, float beltPos) { - int segment = (int) Math.floor(beltPos) * 2; - if (controller.lighter.light == null || segment >= controller.lighter.light.length || segment < 0) + int segment = (int) Math.floor(beltPos); + if (controller.lighter == null || segment >= controller.lighter.lightSegments() || segment < 0) return 0; - return LightTexture.pack(controller.lighter.light[segment], controller.lighter.light[segment + 1]); + return controller.lighter.getPackedLight(segment); } } 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 c5fad852a..78aa5d9f6 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 @@ -35,6 +35,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemS import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult; import com.simibubi.create.foundation.utility.NBTHelper; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -544,8 +545,7 @@ public class BeltTileEntity extends KineticTileEntity { */ @OnlyIn(Dist.CLIENT) class BeltLighter implements LightListener { - // client - public byte[] light; + private byte[] light; public BeltLighter() { initializeLight(); @@ -553,6 +553,23 @@ public class BeltTileEntity extends KineticTileEntity { .addListener(this); } + /** + * Get the number of belt segments represented by the lighter. + * @return The number of segments. + */ + public int lightSegments() { + return light == null ? 0 : light.length / 2; + } + + /** + * Get the light value for a given segment. + * @param segment The segment to get the light value for. + * @return The light value. + */ + public int getPackedLight(int segment) { + return light == null ? 0 : LightTexture.pack(light[segment * 2], light[segment * 2 + 1]); + } + @Override public GridAlignedBB getVolume() { BlockPos endPos = BeltHelper.getPositionForOffset(BeltTileEntity.this, beltLength - 1);