From 8ac42566ec62ce04379d545d362f1694de832380 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 9 Feb 2023 20:07:55 +0000 Subject: [PATCH] Be a little more robust in turtle item rendering See #1328. Also some holiday cleanup, because my commit discipline is terrible. --- .../client/model/turtle/TurtleModelParts.java | 8 +++--- .../render/TurtleBlockEntityRenderer.java | 3 +-- .../shared/turtle/core/TurtleBrain.java | 3 +-- .../computercraft/shared/util/Holiday.java | 26 +++++++++++++++--- .../shared/util/HolidayUtil.java | 27 ------------------- 5 files changed, 30 insertions(+), 37 deletions(-) delete mode 100644 projects/common/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java diff --git a/projects/common/src/client/java/dan200/computercraft/client/model/turtle/TurtleModelParts.java b/projects/common/src/client/java/dan200/computercraft/client/model/turtle/TurtleModelParts.java index 59a995710..ce764e386 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/model/turtle/TurtleModelParts.java +++ b/projects/common/src/client/java/dan200/computercraft/client/model/turtle/TurtleModelParts.java @@ -15,7 +15,6 @@ import dan200.computercraft.client.render.TurtleBlockEntityRenderer; import dan200.computercraft.client.turtle.TurtleUpgradeModellers; import dan200.computercraft.shared.turtle.items.TurtleItem; import dan200.computercraft.shared.util.Holiday; -import dan200.computercraft.shared.util.HolidayUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.resources.ResourceLocation; @@ -71,13 +70,16 @@ public final class TurtleModelParts { } public Combination getCombination(ItemStack stack) { - var turtle = (TurtleItem) stack.getItem(); + var christmas = Holiday.getCurrent() == Holiday.CHRISTMAS; + + if (!(stack.getItem() instanceof TurtleItem turtle)) { + return new Combination(false, null, null, null, christmas, false); + } var colour = turtle.getColour(stack); var leftUpgrade = turtle.getUpgrade(stack, TurtleSide.LEFT); var rightUpgrade = turtle.getUpgrade(stack, TurtleSide.RIGHT); var overlay = turtle.getOverlay(stack); - var christmas = HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS; var label = turtle.getLabel(stack); var flip = label != null && (label.equals("Dinnerbone") || label.equals("Grumm")); diff --git a/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java b/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java index 14930f0d9..77e7b6226 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java +++ b/projects/common/src/client/java/dan200/computercraft/client/render/TurtleBlockEntityRenderer.java @@ -17,7 +17,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.Holiday; -import dan200.computercraft.shared.util.HolidayUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.renderer.MultiBufferSource; @@ -112,7 +111,7 @@ public class TurtleBlockEntityRenderer implements BlockEntityRenderer= 24 && day <= 26) return CHRISTMAS; + return NONE; + } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java b/projects/common/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java deleted file mode 100644 index 22a0610d2..000000000 --- a/projects/common/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.shared.util; - -import java.util.Calendar; - -public final class HolidayUtil { - private HolidayUtil() { - } - - public static Holiday getCurrentHoliday() { - return getHoliday(Calendar.getInstance()); - } - - private static Holiday getHoliday(Calendar calendar) { - var month = calendar.get(Calendar.MONTH); - var day = calendar.get(Calendar.DAY_OF_MONTH); - if (month == Calendar.FEBRUARY && day == 14) return Holiday.VALENTINES; - if (month == Calendar.APRIL && day == 1) return Holiday.APRIL_FOOLS_DAY; - if (month == Calendar.OCTOBER && day == 31) return Holiday.HALLOWEEN; - if (month == Calendar.DECEMBER && day >= 24 && day <= 30) return Holiday.CHRISTMAS; - return Holiday.NONE; - } -}