Skip to content

Commit

Permalink
better code
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Dec 19, 2024
1 parent 2204ef2 commit 0a4cf2b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import static com.minecolonies.core.client.render.CitizenArmorLayer.christmasStack;

/**
* Citizen model.
*/
Expand Down Expand Up @@ -92,10 +90,7 @@ public boolean displayHat(final AbstractEntityCitizen citizen)
{
return false;
}
if (christmasStack != ItemStack.EMPTY && christmasStack != null)
{
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.minecolonies.api.colony.ICitizenDataView;
import com.minecolonies.api.entity.citizen.AbstractEntityCitizen;
import com.minecolonies.api.items.ModItems;
import com.minecolonies.core.MineColonies;
import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down Expand Up @@ -32,9 +30,6 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

import java.time.Clock;
import java.time.LocalDate;
import java.time.Month;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand All @@ -44,7 +39,6 @@ public class CitizenArmorLayer<T extends AbstractEntityCitizen, M extends Humano
{
private final Map<SkullBlock.Type, SkullModelBase> skullModels;
private final Map<UUID, GameProfile> gameProfileMap = new HashMap<>();
public static ItemStack christmasStack = null;

public CitizenArmorLayer(RenderLayerParent<T, M> parentLayer, A innerModel, A outerModel, ModelManager modelManager, final EntityModelSet modelSet)
{
Expand Down Expand Up @@ -126,29 +120,10 @@ 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())
{
if (christmasStack == null)
{
if (MineColonies.getConfig().getServer().holidayFeatures.get() && LocalDate.now(Clock.systemDefaultZone()).getMonth() == Month.DECEMBER)
{
christmasStack = new ItemStack(ModItems.santaHat);
}
else
{
christmasStack = ItemStack.EMPTY;
}
}

if (christmasStack != ItemStack.EMPTY && equipmentSlot == EquipmentSlot.HEAD)
{
itemstack = christmasStack;
}
else
{
itemstack = citizen.getItemBySlot(equipmentSlot);
}
itemstack = citizen.getItemBySlot(equipmentSlot);
}
Item armorItem = itemstack.getItem();

Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/minecolonies/core/colony/CitizenDataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -43,6 +50,11 @@
*/
public class CitizenDataView implements ICitizenDataView
{
/**
* Santa Hat.
*/
private static ItemStack displaySantaHat = null;

private static final String TAG_HELD_ITEM_SLOT = "HeldItemSlot";

/**
Expand Down Expand Up @@ -614,4 +626,31 @@ public boolean equals(final Object o)

return id == data.getId();
}

@Override
public ItemStack getDisplayArmor(final EquipmentSlot equipmentSlot)
{
if (displaySantaHat == null)
{
if (MineColonies.getConfig().getServer().holidayFeatures.get() && LocalDate.now(Clock.systemDefaultZone()).getMonth() == Month.DECEMBER)
{
displaySantaHat = new ItemStack(ModItems.santaHat);
}
else
{
displaySantaHat = ItemStack.EMPTY;
}
}

final ItemStack currentHat = getInventory().getArmorInSlot(equipmentSlot);
if (!currentHat.isEmpty())
{
return currentHat;
}
if (displaySantaHat != ItemStack.EMPTY && equipmentSlot == EquipmentSlot.HEAD)
{
return displaySantaHat;
}
return getInventory().getArmorInSlot(equipmentSlot);
}
}

0 comments on commit 0a4cf2b

Please sign in to comment.