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.
This commit is contained in:
Jozufozu 2023-12-08 18:38:40 -08:00
parent 1d318ecb02
commit ec6dbfbf49
3 changed files with 17 additions and 13 deletions

View file

@ -31,7 +31,7 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> 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<BellBlockEntity> 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<BellBlockEntity> 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

View file

@ -90,6 +90,7 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
}
bottom.setRotation(baseRotation);
bottom.setChanged();
applyLidTransform(lidProgress.get(partialTick));

View file

@ -71,6 +71,9 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
base = createBaseInstance(texture).setTransform(stack);
lid = createLidInstance(texture).setTransform(stack);
base.setChanged();
lid.setChanged();
super.init(partialTick);
}