Simplify usage of IItemRenderProperties::getArmorModel (#8349)

This commit is contained in:
KnightMiner authored and GitHub committed 2022-01-22 00:37:55 +01:00
1 parent 5f0d4abf23
commit fd522d38b0
5 files changed
+204 -15

No files matched your search

@@ -26,6 +26,7 @@ import com.mojang.datafixers.util.Either;
import net.minecraft.client.gui.chat.NarratorChatListener;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
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;
@@ -279,10 +280,24 @@ public class ForgeHooksClient
renderType.set(layer);
}
public static <A extends HumanoidModel<?>> A getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot slot, A _default)
public static Model getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot slot, HumanoidModel<?> _default)
{
A model = RenderProperties.get(itemStack).getArmorModel(entityLiving, itemStack, slot, _default);
return model == null ? _default : model;
return RenderProperties.get(itemStack).getBaseArmorModel(entityLiving, itemStack, slot, _default);
}
/** Copies humanoid model properties from the original model to another, used for armor models */
@SuppressWarnings("unchecked")
public static <T extends LivingEntity> void copyModelProperties(HumanoidModel<T> original, HumanoidModel<?> replacement)
{
// this function does not make use of the <T> generic, so the unchecked cast should be safe
original.copyPropertiesTo((HumanoidModel<T>)replacement);
replacement.head.visible = original.head.visible;
replacement.hat.visible = original.hat.visible;
replacement.body.visible = original.body.visible;
replacement.rightArm.visible = original.rightArm.visible;
replacement.leftArm.visible = original.leftArm.visible;
replacement.rightLeg.visible = original.rightLeg.visible;
replacement.leftLeg.visible = original.leftLeg.visible;
}
//This properly moves the domain, if provided, to the front of the string before concatenating
@@ -22,12 +22,16 @@ package net.minecraftforge.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public interface IItemRenderProperties
{
IItemRenderProperties DUMMY = new IItemRenderProperties()
@@ -53,13 +57,40 @@ public interface IItemRenderProperties
* @param itemStack The itemStack to render the model of
* @param armorSlot The slot the armor is in
* @param _default Original armor model. Will have attributes set.
* @return A ModelBiped to render instead of the default
* @return A HumanoidModel to render instead of the default, will have the relevant properties copied in {@link #getBaseArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel).
* Returning null will cause the default to render.
* @see #getBaseArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)
*/
default <A extends HumanoidModel<?>> A getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, A _default)
@Nullable
default HumanoidModel<?> getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, HumanoidModel<?> _default)
{
return null;
}
/**
* Override this method to return a generic model rather than a {@link HumanoidModel}. More ideal for wrapping the original model or returning non-standard models like elytra wings.
* By default, this hook copies in the model properties from the default into the model returned by {@link #getArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)},
* so if you override this method you are responsible for copying properties you care about
*
* @param entityLiving The entity wearing the armor
* @param itemStack The itemStack to render the model of
* @param armorSlot The slot the armor is in
* @param _default Original armor model. Will have attributes set.
* @return A Model to render instead of the default
* @see #getArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)
*/
@Nonnull
default Model getBaseArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, HumanoidModel<?> _default)
{
HumanoidModel<?> replacement = getArmorModel(entityLiving, itemStack, armorSlot, _default);
if (replacement != null && replacement != _default)
{
ForgeHooksClient.copyModelProperties(_default, replacement);
return replacement;
}
return _default;
}
/**
* Called when the client starts rendering the HUD, for whatever item the player
* currently has as a helmet. This is where pumpkins would render there overlay.