From 60a8933952c8233d54a6ab93da044ef1b4e0cf29 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Thu, 19 Dec 2024 22:51:31 +0100 Subject: [PATCH] fix christmas! (#10538) fix christmas and halloween event code --- .../client/render/modeltype/CitizenModel.java | 2 +- .../render/modeltype/ISimpleModelType.java | 35 ++++++++++++++++-- .../render/modeltype/SimpleModelType.java | 5 +++ .../api/colony/ICitizenDataView.java | 9 +++++ .../core/client/render/CitizenArmorLayer.java | 12 +------ .../core/colony/CitizenDataView.java | 36 +++++++++++++++++++ .../com/minecolonies/core/colony/Colony.java | 10 ------ .../core/entity/citizen/EntityCitizen.java | 13 ------- 8 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/minecolonies/api/client/render/modeltype/CitizenModel.java b/src/main/java/com/minecolonies/api/client/render/modeltype/CitizenModel.java index 95f61bd2f55..676c1fa98d9 100755 --- a/src/main/java/com/minecolonies/api/client/render/modeltype/CitizenModel.java +++ b/src/main/java/com/minecolonies/api/client/render/modeltype/CitizenModel.java @@ -89,6 +89,6 @@ public boolean displayHat(final AbstractEntityCitizen citizen) { return false; } - return citizen.getCitizenDataView() == null || (citizen.getCitizenDataView().getInventory().getArmorInSlot(EquipmentSlot.HEAD).isEmpty() && citizen.getCitizenDataView().getCustomTextureUUID() == null); + return citizen.getCitizenDataView() == null || (citizen.getCitizenDataView().getDisplayArmor(EquipmentSlot.HEAD).isEmpty() && citizen.getCitizenDataView().getCustomTextureUUID() == null); } } 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/api/colony/ICitizenDataView.java b/src/main/java/com/minecolonies/api/colony/ICitizenDataView.java index 269d80c9734..20b6e40f3b1 100755 --- a/src/main/java/com/minecolonies/api/colony/ICitizenDataView.java +++ b/src/main/java/com/minecolonies/api/colony/ICitizenDataView.java @@ -11,6 +11,8 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -227,4 +229,11 @@ public interface ICitizenDataView extends ICitizen * @return the uuid. */ UUID getCustomTextureUUID(); + + /** + * Get Armor in slot of citizen data view. + * @param equipmentSlot the equipment slot to get it from. + * @return the armor in the slot. + */ + ItemStack getDisplayArmor(EquipmentSlot equipmentSlot); } diff --git a/src/main/java/com/minecolonies/core/client/render/CitizenArmorLayer.java b/src/main/java/com/minecolonies/core/client/render/CitizenArmorLayer.java index 821ab946225..8a70c23b12f 100644 --- a/src/main/java/com/minecolonies/core/client/render/CitizenArmorLayer.java +++ b/src/main/java/com/minecolonies/core/client/render/CitizenArmorLayer.java @@ -3,7 +3,6 @@ import com.minecolonies.api.colony.ICitizenDataView; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Axis; @@ -20,20 +19,12 @@ import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.model.ModelManager; -import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.WalkAnimationState; import net.minecraft.world.item.*; import net.minecraft.world.item.armortrim.ArmorTrim; -import net.minecraft.world.level.block.AbstractSkullBlock; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.SkullBlock; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -42,7 +33,6 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; @OnlyIn(Dist.CLIENT) public class CitizenArmorLayer, A extends HumanoidModel> extends HumanoidArmorLayer @@ -130,7 +120,7 @@ public void render( private void renderArmorPiece(PoseStack poseStack, MultiBufferSource bufferSource, T citizen, EquipmentSlot equipmentSlot, int light, A armor, final ICitizenDataView citizenDataView) { - ItemStack itemstack = citizenDataView.getInventory().getArmorInSlot(equipmentSlot); + ItemStack itemstack = citizenDataView.getDisplayArmor(equipmentSlot); if (itemstack.isEmpty()) { itemstack = citizen.getItemBySlot(equipmentSlot); diff --git a/src/main/java/com/minecolonies/core/colony/CitizenDataView.java b/src/main/java/com/minecolonies/core/colony/CitizenDataView.java index c064ac18d32..d79e3efd36f 100644 --- a/src/main/java/com/minecolonies/core/colony/CitizenDataView.java +++ b/src/main/java/com/minecolonies/core/colony/CitizenDataView.java @@ -13,9 +13,11 @@ import com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenHappinessHandler; import com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenSkillHandler; import com.minecolonies.api.inventory.InventoryCitizen; +import com.minecolonies.api.items.ModItems; import com.minecolonies.api.util.Tuple; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.api.util.constant.Suppression; +import com.minecolonies.core.MineColonies; import com.minecolonies.core.colony.interactionhandling.ServerCitizenInteraction; import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenHappinessHandler; import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenSkillHandler; @@ -28,10 +30,15 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Clock; +import java.time.LocalDate; +import java.time.Month; import java.util.*; import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_OFFHAND_HELD_ITEM_SLOT; @@ -43,6 +50,11 @@ */ public class CitizenDataView implements ICitizenDataView { + /** + * Santa Hat. + */ + private static ItemStack cachedDisplaySantaHat = null; + private static final String TAG_HELD_ITEM_SLOT = "HeldItemSlot"; /** @@ -614,4 +626,28 @@ public boolean equals(final Object o) return id == data.getId(); } + + @Override + public ItemStack getDisplayArmor(final EquipmentSlot equipmentSlot) + { + if (cachedDisplaySantaHat == null) + { + if (MineColonies.getConfig().getServer().holidayFeatures.get() && LocalDate.now(Clock.systemDefaultZone()).getMonth() == Month.DECEMBER) + { + cachedDisplaySantaHat = new ItemStack(ModItems.santaHat); + } + else + { + cachedDisplaySantaHat = ItemStack.EMPTY; + } + } + + final ItemStack currentHat = getInventory().getArmorInSlot(equipmentSlot); + if (currentHat.isEmpty() && cachedDisplaySantaHat != null && cachedDisplaySantaHat != ItemStack.EMPTY && equipmentSlot == EquipmentSlot.HEAD) + { + return cachedDisplaySantaHat; + } + + return currentHat; + } } 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; } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index be1a8ff21d5..c1897d4e546 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -783,19 +783,6 @@ public int getMaxAirSupply() */ private boolean updateVisualData() { - final ItemStack hat = getItemBySlot(EquipmentSlot.HEAD); - if (LocalDate.now(Clock.systemDefaultZone()).getMonth() == Month.DECEMBER - && MineColonies.getConfig().getServer().holidayFeatures.get()) - { - if (hat.isEmpty()) - { - this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(ModItems.santaHat)); - } - } - else if (!hat.isEmpty() && hat.getItem() == ModItems.santaHat) - { - this.setItemSlot(EquipmentSlot.HEAD, ItemStackUtils.EMPTY); - } this.setCustomNameVisible(MineColonies.getConfig().getServer().alwaysRenderNameTag.get()); if (!citizenColonyHandler.getColonyOrRegister().getTextureStyleId().equals(getEntityData().get(DATA_STYLE)))