From 1f1f611dcff52a00a808c5d3f131073e50110818 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Thu, 19 Dec 2024 22:39:54 +0100 Subject: [PATCH] also fix halloween --- .../render/modeltype/ISimpleModelType.java | 35 +++++++++++++++++-- .../render/modeltype/SimpleModelType.java | 5 +++ .../com/minecolonies/core/colony/Colony.java | 10 ------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/minecolonies/api/client/render/modeltype/ISimpleModelType.java b/src/main/java/com/minecolonies/api/client/render/modeltype/ISimpleModelType.java index e5db1fc4846..d0173c4af37 100755 --- a/src/main/java/com/minecolonies/api/client/render/modeltype/ISimpleModelType.java +++ b/src/main/java/com/minecolonies/api/client/render/modeltype/ISimpleModelType.java @@ -2,10 +2,15 @@ import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.util.constant.Constants; +import com.minecolonies.core.MineColonies; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; +import java.time.LocalDateTime; +import java.time.Month; + +import static com.minecolonies.api.client.render.modeltype.SimpleModelType.cachedHalloweenStyle; import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_STYLE; import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_TEXTURE_SUFFIX; @@ -44,10 +49,30 @@ public interface ISimpleModelType extends IModelType */ default ResourceLocation getTexture(@NotNull final AbstractEntityCitizen entityCitizen) { + if (cachedHalloweenStyle == null) + { + if (MineColonies.getConfig().getServer().holidayFeatures.get() && + ((LocalDateTime.now().getDayOfMonth() >= 29 && LocalDateTime.now().getMonth() == Month.OCTOBER) + || (LocalDateTime.now().getDayOfMonth() <= 2 && LocalDateTime.now().getMonth() == Month.NOVEMBER))) + { + cachedHalloweenStyle = "nether"; + } + else + { + cachedHalloweenStyle = ""; + } + } + + String style = entityCitizen.getEntityData().get(DATA_STYLE); + if (!cachedHalloweenStyle.isEmpty()) + { + style = cachedHalloweenStyle; + } + final int moddedTextureId = (entityCitizen.getTextureId() % getNumTextures()) + 1; final String textureIdentifier = getName().getPath() + (entityCitizen.isFemale() ? "female" : "male") + moddedTextureId + entityCitizen.getEntityData().get(DATA_TEXTURE_SUFFIX); - final ResourceLocation modified = new ResourceLocation(Constants.MOD_ID, BASE_FOLDER + entityCitizen.getEntityData().get(DATA_STYLE) + "/" + textureIdentifier + ".png"); + final ResourceLocation modified = new ResourceLocation(Constants.MOD_ID, BASE_FOLDER + style + "/" + textureIdentifier + ".png"); if (Minecraft.getInstance().getResourceManager().getResource(modified).isPresent()) { return modified; @@ -58,10 +83,16 @@ default ResourceLocation getTexture(@NotNull final AbstractEntityCitizen entityC default ResourceLocation getTextureIcon(@NotNull final AbstractEntityCitizen entityCitizen) { + String style = entityCitizen.getEntityData().get(DATA_STYLE); + if (cachedHalloweenStyle != null && !cachedHalloweenStyle.isEmpty()) + { + style = cachedHalloweenStyle; + } + final int moddedTextureId = (entityCitizen.getTextureId() % getNumTextures()) + 1; final String textureIdentifier = getTextureBase() + (entityCitizen.isFemale() ? "female" : "male") + moddedTextureId + entityCitizen.getEntityData() .get(DATA_TEXTURE_SUFFIX); - return new ResourceLocation(Constants.MOD_ID, "textures/entity_icon/citizen/" + entityCitizen.getEntityData().get(DATA_STYLE) + "/" + textureIdentifier + ".png"); + return new ResourceLocation(Constants.MOD_ID, "textures/entity_icon/citizen/" + style + "/" + textureIdentifier + ".png"); } } diff --git a/src/main/java/com/minecolonies/api/client/render/modeltype/SimpleModelType.java b/src/main/java/com/minecolonies/api/client/render/modeltype/SimpleModelType.java index 2681a37d6c5..63168bfbdf8 100644 --- a/src/main/java/com/minecolonies/api/client/render/modeltype/SimpleModelType.java +++ b/src/main/java/com/minecolonies/api/client/render/modeltype/SimpleModelType.java @@ -8,6 +8,11 @@ */ public class SimpleModelType implements ISimpleModelType { + /** + * Halloween style string. Null = uninitialized. + */ + static String cachedHalloweenStyle = null; + /** * String describing the citizen. Used by the renderer. Starts with a capital, and does not contain spaces or other special characters. */ diff --git a/src/main/java/com/minecolonies/core/colony/Colony.java b/src/main/java/com/minecolonies/core/colony/Colony.java index 1400e409339..646e7dae166 100644 --- a/src/main/java/com/minecolonies/core/colony/Colony.java +++ b/src/main/java/com/minecolonies/core/colony/Colony.java @@ -25,7 +25,6 @@ import com.minecolonies.api.util.constant.Constants; import com.minecolonies.api.util.constant.NbtTagConstants; import com.minecolonies.api.util.constant.Suppression; -import com.minecolonies.core.MineColonies; import com.minecolonies.core.Network; import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.modules.SettingsModule; @@ -65,8 +64,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.time.LocalDateTime; -import java.time.Month; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -1867,13 +1864,6 @@ public void setTextureStyle(final String style) @Override public String getTextureStyleId() { - if (MineColonies.getConfig().getServer().holidayFeatures.get() && - ((LocalDateTime.now().getDayOfMonth() >= 29 && LocalDateTime.now().getMonth() == Month.OCTOBER) - || (LocalDateTime.now().getDayOfMonth() <= 2 && LocalDateTime.now().getMonth() == Month.NOVEMBER))) - { - return "nether"; - } - return this.textureStyle; }