diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java index 0fcb9e109..86e523d75 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -57,6 +57,11 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer actor) { Template.BlockInfo blockInfo = actor.getLeft(); 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 d77eb4e69..c4673140c 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 @@ -79,13 +79,13 @@ public class ArmTileEntity extends KineticTileEntity { phase = Phase.SEARCH_INPUTS; previousTarget = ArmAngleTarget.NO_TARGET; baseAngle = new InterpolatedAngle(); - baseAngle.set(previousTarget.baseAngle); + baseAngle.init(previousTarget.baseAngle); lowerArmAngle = new InterpolatedAngle(); - lowerArmAngle.set(previousTarget.lowerArmAngle); + lowerArmAngle.init(previousTarget.lowerArmAngle); upperArmAngle = new InterpolatedAngle(); - upperArmAngle.set(previousTarget.upperArmAngle); + upperArmAngle.init(previousTarget.upperArmAngle); headAngle = new InterpolatedAngle(); - headAngle.set(previousTarget.headAngle); + headAngle.init(previousTarget.headAngle); clawAngle = new InterpolatedAngle(); previousBaseAngle = previousTarget.baseAngle; updateInteractionPoints = true; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java index ebc1e712f..65f459580 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java @@ -12,6 +12,11 @@ public class InterpolatedValue { this.value = value; return this; } + + public InterpolatedValue init(float value) { + this.lastValue = this.value = value; + return this; + } public float get(float partialTicks) { return MathHelper.lerp(partialTicks, lastValue, value); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 80574a142..500a7a930 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -57,11 +57,7 @@ public abstract class InstancedTileRenderer

{ int dY = pos.getY() - cY; int dZ = pos.getZ() - cZ; - int dSq = dX * dX + dY * dY + dZ * dZ; - - int divisor = (dSq / 1024) + 1; - - if (frame % divisor == 0) + if ((frame % getUpdateDivisor(dX, dY, dZ)) == 0) instance.tick(); } } @@ -88,21 +84,7 @@ public abstract class InstancedTileRenderer

{ continue; } - BlockPos pos = dyn.getWorldPosition(); - - int dX = pos.getX() - cX; - int dY = pos.getY() - cY; - int dZ = pos.getZ() - cZ; - - float dot = dX * lookX + dY * lookY + dZ * lookZ; - - if (dot < 0) continue; // is it behind the camera? - - int dSq = dX * dX + dY * dY + dZ * dZ; - - int divisor = (dSq / 1024) + 1; // https://www.desmos.com/calculator/aaycpludsy - - if (frame % divisor == 0) + if (shouldTick(dyn.getWorldPosition(), lookX, lookY, lookZ, cX, cY, cZ)) dyn.beginFrame(); } } @@ -207,6 +189,24 @@ public abstract class InstancedTileRenderer

{ } } + protected boolean shouldTick(BlockPos worldPos, float lookX, float lookY, float lookZ, int cX, int cY, int cZ) { + int dX = worldPos.getX() - cX; + int dY = worldPos.getY() - cY; + int dZ = worldPos.getZ() - cZ; + + float dot = dX * lookX + dY * lookY + dZ * lookZ; + + if (dot < 0) return false; // is it behind the camera? + + return (frame % getUpdateDivisor(dX, dY, dZ)) == 0; + } + + protected int getUpdateDivisor(int dX, int dY, int dZ) { + int dSq = dX * dX + dY * dY + dZ * dZ; + + return (dSq / 1024) + 1; + } + private void addInternal(TileEntity tile) { getInstance(tile, true); }