Skip to content

Commit

Permalink
[1.21.4] Fix armor property copying and tintable armor rendering (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Dec 18, 2024
1 parent f64d2c7 commit 20c22e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
int p_371309_,
@Nullable ResourceLocation p_371639_
) {
+ p_371731_ = getArmorModelHook(p_371670_, p_387484_, p_371731_);
+ net.neoforged.neoforge.client.extensions.common.IClientItemExtensions extensions = net.neoforged.neoforge.client.extensions.common.IClientItemExtensions.of(p_371670_);
+ p_371731_ = extensions.getGenericArmorModel(p_371670_, p_387484_, p_371731_);
List<EquipmentClientInfo.Layer> list = this.equipmentAssets.get(p_387603_).getLayers(p_387484_);
if (!list.isEmpty()) {
- int i = p_371670_.is(ItemTags.DYEABLE) ? DyedItemColor.getOrDefault(p_371670_, 0) : 0;
+ net.neoforged.neoforge.client.extensions.common.IClientItemExtensions extensions = net.neoforged.neoforge.client.extensions.common.IClientItemExtensions.of(p_371670_);
+ int i = extensions.getDefaultDyeColor(p_371670_);
boolean flag = p_371670_.hasFoil();

Expand All @@ -29,17 +29,3 @@
}

ArmorTrim armortrim = p_371670_.get(DataComponents.TRIM);
@@ -100,6 +_,13 @@
} else {
return -1;
}
+ }
+
+ /**
+ * Hook to allow item-sensitive armor model. for HumanoidArmorLayer.
+ */
+ protected net.minecraft.client.model.Model getArmorModelHook(ItemStack itemStack, EquipmentClientInfo.LayerType layerType, Model model) {
+ return net.neoforged.neoforge.client.ClientHooks.getArmorModel(itemStack, layerType, model);
}

@OnlyIn(Dist.CLIENT)
5 changes: 0 additions & 5 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.multiplayer.ClientLevel;
Expand Down Expand Up @@ -299,10 +298,6 @@ public static void onBlockColorsInit(BlockColors blockColors) {
ModLoader.postEvent(new RegisterColorHandlersEvent.Block(blockColors));
}

public static Model getArmorModel(ItemStack itemStack, EquipmentClientInfo.LayerType layerType, Model _default) {
return IClientItemExtensions.of(itemStack).getGenericArmorModel(itemStack, layerType, _default);
}

/** Copies humanoid model properties from the original model to another, used for armor models */
@SuppressWarnings("unchecked")
public static <T extends HumanoidRenderState> void copyModelProperties(HumanoidModel<T> original, HumanoidModel<?> replacement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ARGB;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.HumanoidArm;
Expand All @@ -25,6 +24,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.DyedItemColor;
import net.neoforged.fml.LogicalSide;
import net.neoforged.neoforge.client.ClientHooks;
import net.neoforged.neoforge.client.IArmPoseTransformer;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -116,8 +116,9 @@ default Model getHumanoidArmorModel(ItemStack itemStack, EquipmentClientInfo.Lay
default Model getGenericArmorModel(ItemStack itemStack, EquipmentClientInfo.LayerType layerType, Model original) {
Model replacement = getHumanoidArmorModel(itemStack, layerType, original);
if (replacement != original) {
// FIXME: equipment rendering deals with a plain Model now
//ClientHooks.copyModelProperties(original, replacement);
if (original instanceof HumanoidModel<?> originalHumanoid && replacement instanceof HumanoidModel<?> replacementHumanoid) {
ClientHooks.copyModelProperties(originalHumanoid, replacementHumanoid);
}
return replacement;
}
return original;
Expand Down Expand Up @@ -203,7 +204,7 @@ default int getArmorLayerTintColor(ItemStack stack, EquipmentClientInfo.Layer la
* @return a default color for the layer, in ARGB format
*/
default int getDefaultDyeColor(ItemStack stack) {
return stack.is(ItemTags.DYEABLE) ? ARGB.opaque(DyedItemColor.getOrDefault(stack, 0)) : 0;
return stack.is(ItemTags.DYEABLE) ? DyedItemColor.getOrDefault(stack, 0) : 0;
}

/**
Expand Down

0 comments on commit 20c22e6

Please sign in to comment.