From ec6dbfbf492b468131b26ebc8b37280c7316d3ae Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Fri, 8 Dec 2023 18:38:40 -0800 Subject: [PATCH] Un unchanged - Call setChanged in various visuals' #init. - Not everything needs it because some just call their frame update methods right away. - Improve lazy update logic for bells. --- .../jozufozu/flywheel/vanilla/BellVisual.java | 26 +++++++++---------- .../flywheel/vanilla/ChestVisual.java | 1 + .../flywheel/vanilla/ShulkerBoxVisual.java | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java index 479bde389..d6126d5af 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java @@ -31,7 +31,7 @@ public class BellVisual extends AbstractBlockEntityVisual imple private OrientedInstance bell; - private float lastRingTime = Float.NaN; + private boolean wasShaking = false; public BellVisual(VisualizationContext ctx, BellBlockEntity blockEntity) { super(ctx, blockEntity); @@ -42,6 +42,8 @@ public class BellVisual extends AbstractBlockEntityVisual imple bell = createBellInstance().setPivot(0.5f, 0.75f, 0.5f) .setPosition(getVisualPosition()); + bell.setChanged(); + updateRotation(partialTick); super.init(partialTick); @@ -62,25 +64,23 @@ public class BellVisual extends AbstractBlockEntityVisual imple } private void updateRotation(float partialTick) { - float ringTime = (float) blockEntity.ticks + partialTick; - - if (ringTime == lastRingTime) { - return; - } - lastRingTime = ringTime; - if (blockEntity.shaking) { + float ringTime = (float) blockEntity.ticks + partialTick; float angle = Mth.sin(ringTime / (float) Math.PI) / (4.0F + ringTime / 3.0F); Vector3f ringAxis = blockEntity.clickDirection.getCounterClockWise() .step(); - bell.setRotation(new Quaternionf(new AxisAngle4f(angle, ringAxis))); - } else { - bell.setRotation(new Quaternionf()); - } + bell.setRotation(new Quaternionf(new AxisAngle4f(angle, ringAxis))) + .setChanged(); - bell.setChanged(); + wasShaking = true; + } else if (wasShaking) { + bell.setRotation(new Quaternionf()) + .setChanged(); + + wasShaking = false; + } } @Override diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java index 15311ce24..01df7480c 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java @@ -90,6 +90,7 @@ public class ChestVisual extends Abstrac } bottom.setRotation(baseRotation); + bottom.setChanged(); applyLidTransform(lidProgress.get(partialTick)); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java index b0c99e4fb..c04326622 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java @@ -71,6 +71,9 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual