Skip to content

Commit a2835bf

Browse files
committed
Fixes #432
1 parent 7398ab8 commit a2835bf

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

common/src/main/java/whocraft/tardis_refined/client/model/blockentity/console/FactoryConsoleModel.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, i
5151
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
5252
root().getAllParts().forEach(ModelPart::resetPose);
5353
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
54-
if (globalConsoleBlock == null) return;
5554

56-
Boolean powered = globalConsoleBlock.getBlockState() == null ? true : globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
55+
// Exit early if globalConsoleBlock is null
56+
if (globalConsoleBlock == null) {
57+
root().render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
58+
return;
59+
}
5760

61+
// Safely determine if the console is powered
62+
boolean powered = globalConsoleBlock.getBlockState() != null
63+
&& globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
5864

5965
if (powered) {
60-
6166
if (!globalConsoleBlock.powerOn.isStarted()) {
6267
globalConsoleBlock.powerOff.stop();
6368
globalConsoleBlock.powerOn.start(Minecraft.getInstance().player.tickCount);
@@ -72,30 +77,30 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
7277
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);
7378
} else {
7479
// Handle idle animation
75-
if (TRConfig.CLIENT.PLAY_CONSOLE_IDLE_ANIMATIONS.get() && globalConsoleBlock != null) {
80+
if (TRConfig.CLIENT.PLAY_CONSOLE_IDLE_ANIMATIONS.get()) {
7681
this.animate(globalConsoleBlock.liveliness, IDLE, Minecraft.getInstance().player.tickCount);
7782
}
7883
}
79-
8084
} else {
81-
if (globalConsoleBlock != null) {
82-
if (!globalConsoleBlock.powerOff.isStarted()) {
83-
globalConsoleBlock.powerOn.stop();
84-
globalConsoleBlock.powerOff.start(Minecraft.getInstance().player.tickCount);
85-
}
86-
this.animate(globalConsoleBlock.powerOff, POWER_OFF, Minecraft.getInstance().player.tickCount);
85+
if (!globalConsoleBlock.powerOff.isStarted()) {
86+
globalConsoleBlock.powerOn.stop();
87+
globalConsoleBlock.powerOff.start(Minecraft.getInstance().player.tickCount);
8788
}
89+
this.animate(globalConsoleBlock.powerOff, POWER_OFF, Minecraft.getInstance().player.tickCount);
8890
}
8991

90-
float rot = -125 - (30 * ((float) reactions.getThrottleStage() / TardisPilotingManager.MAX_THROTTLE_STAGE));
91-
this.throttleLever.xRot = rot;
92+
// Update throttle lever and handbrake animations
93+
float throttleRotation = -125 - (30 * ((float) reactions.getThrottleStage() / TardisPilotingManager.MAX_THROTTLE_STAGE));
94+
this.throttleLever.xRot = throttleRotation;
9295

9396
this.handbrake.xRot = reactions.isHandbrakeEngaged() ? -155f : -125f;
94-
root().render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
9597

98+
// Render the model
99+
root().render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
96100
}
97101

98102

103+
99104
@Override
100105
public ModelPart root() {
101106
return root;

common/src/main/java/whocraft/tardis_refined/client/model/blockentity/console/VictorianConsoleModel.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -927,25 +927,29 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
927927
root().getAllParts().forEach(ModelPart::resetPose);
928928
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
929929

930-
Boolean powered = globalConsoleBlock.getBlockState() == null ? true : globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
930+
boolean powered = globalConsoleBlock != null
931+
&& globalConsoleBlock.getBlockState() != null
932+
&& globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
931933

932934
if (powered) {
933-
if (!globalConsoleBlock.powerOn.isStarted()) {
934-
globalConsoleBlock.powerOff.stop();
935-
globalConsoleBlock.powerOn.start(Minecraft.getInstance().player.tickCount);
936-
}
937-
this.animate(globalConsoleBlock.powerOn, POWER_ON, Minecraft.getInstance().player.tickCount);
938-
939-
if (reactions.isCrashing()) {
940-
// Handle crashing animation
941-
this.animate(reactions.CRASHING_ANIMATION, CRASH, Minecraft.getInstance().player.tickCount);
942-
} else if (reactions.isFlying()) {
943-
// Handle flying animation
944-
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);
945-
} else {
946-
// Handle idle animation
947-
if (TRConfig.CLIENT.PLAY_CONSOLE_IDLE_ANIMATIONS.get() && globalConsoleBlock != null) {
948-
this.animate(globalConsoleBlock.liveliness, IDLE, Minecraft.getInstance().player.tickCount);
935+
if (globalConsoleBlock != null) {
936+
if (!globalConsoleBlock.powerOn.isStarted()) {
937+
globalConsoleBlock.powerOff.stop();
938+
globalConsoleBlock.powerOn.start(Minecraft.getInstance().player.tickCount);
939+
}
940+
this.animate(globalConsoleBlock.powerOn, POWER_ON, Minecraft.getInstance().player.tickCount);
941+
942+
if (reactions.isCrashing()) {
943+
// Handle crashing animation
944+
this.animate(reactions.CRASHING_ANIMATION, CRASH, Minecraft.getInstance().player.tickCount);
945+
} else if (reactions.isFlying()) {
946+
// Handle flying animation
947+
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);
948+
} else {
949+
// Handle idle animation
950+
if (TRConfig.CLIENT.PLAY_CONSOLE_IDLE_ANIMATIONS.get()) {
951+
this.animate(globalConsoleBlock.liveliness, IDLE, Minecraft.getInstance().player.tickCount);
952+
}
949953
}
950954
}
951955
} else {
@@ -964,6 +968,7 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
964968
root().render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
965969
}
966970

971+
967972
@Override
968973
public ResourceLocation getDefaultTexture() {
969974
return VICTORIAN_TEXTURE;

0 commit comments

Comments
 (0)