Skip to content

Commit

Permalink
Fix errors getting logged due to us not using vanilla texture locations
Browse files Browse the repository at this point in the history
Just returning diamond armor everywhere since we don't use that texture. I'm sure some performance mod is still going to be broken though
  • Loading branch information
KnightMiner committed May 15, 2024
1 parent e7e090f commit 7c1d1d0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected AbstractArmorModel() {
protected void setup(LivingEntity living, ItemStack stack, EquipmentSlot slot, HumanoidModel<?> base) {
this.base = base;
this.hasGlint = stack.hasFoil();
this.textureType = slot == EquipmentSlot.LEGS ? TextureType.LEGGINGS : TextureType.ARMOR;
this.textureType = TextureType.fromSlot(slot);
if (slot == EquipmentSlot.CHEST) {
this.hasWings = ModifierUtil.checkVolatileFlag(stack, ModifiableArmorItem.ELYTRA);
if (hasWings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package slimeknights.tconstruct.library.tools.helper;

import net.minecraft.util.Mth;
import net.minecraft.world.entity.EquipmentSlot;

import static net.minecraft.world.damagesource.CombatRules.getDamageAfterAbsorb;

Expand Down Expand Up @@ -116,4 +117,17 @@ public static float getDamageForEvent(float originalDamage, float armor, float t
// final damage: A-1(V-1(M(A(x))))
return damage;
}

private static final String DIAMOND_ARMOR = "textures/models/armor/diamond_layer_1.png";
private static final String DIAMOND_LEGGINGS = "textures/models/armor/diamond_layer_2.png";

/**
* We override the armor model to not use the "vanilla" texture in favor of our own system that fetches the texture from NBT.
* However, this means vanilla constructs some non-existing textures for us producing errors in the log.
* Since we don't end up using that texture, bypass the error by just returning a vanilla texture.
* We would just use our system, but it notably supports returning no texture to not render (would still lead to errors) and requires unneeded stack parsing, so faster to just use an arbitrary texture we know exists.
*/
public static String getDummyArmorTexture(EquipmentSlot slot) {
return slot == EquipmentSlot.LEGS ? DIAMOND_LEGGINGS : DIAMOND_ARMOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
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 net.minecraftforge.client.extensions.common.IClientItemExtensions;
import slimeknights.tconstruct.library.client.armor.MaterialArmorModel;
import slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial;
import slimeknights.tconstruct.library.tools.helper.ArmorUtil;
import slimeknights.tconstruct.library.tools.item.armor.texture.MaterialArmorTextureSupplier.MaterialSetCache;
import slimeknights.tconstruct.tools.item.ArmorSlotType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Consumer;

/** Armor item for an item with multiple materials */
Expand All @@ -22,6 +25,12 @@ public MaterialArmorItem(ModifiableArmorMaterial material, ArmorSlotType slotTyp
this.cache = MaterialSetCache.FACTORY.apply(material.getId());
}

@Nullable
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return ArmorUtil.getDummyArmorTexture(slot);
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
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.item.ItemStack;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import slimeknights.tconstruct.library.client.armor.MultilayerArmorModel;
import slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial;
import slimeknights.tconstruct.library.tools.helper.ArmorUtil;
import slimeknights.tconstruct.library.tools.item.armor.texture.ArmorTextureSupplier;
import slimeknights.tconstruct.tools.item.ArmorSlotType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Consumer;
import java.util.function.Function;

Expand All @@ -28,6 +31,12 @@ public MultilayerArmorItem(ModifiableArmorMaterial material, ArmorSlotType slot,
this(material, slot, properties, textures.apply(material.getId()));
}

@Nullable
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return ArmorUtil.getDummyArmorTexture(slot);
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package slimeknights.tconstruct.library.tools.item.armor.texture;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import slimeknights.mantle.data.listener.ResourceValidator;
import slimeknights.mantle.data.registry.GenericLoaderRegistry;
Expand Down Expand Up @@ -29,5 +30,12 @@ public ArmorTexture(String path) {
}

/** Texture variants, armor is used for helmet, chestplate, and boots, while leggings is leggings and wings is on chest for elytra */
enum TextureType { ARMOR, LEGGINGS, WINGS }
enum TextureType {
ARMOR, LEGGINGS, WINGS;

/** Gets the type for the given slot */
public static TextureType fromSlot(EquipmentSlot slot) {
return slot == EquipmentSlot.LEGS ? LEGGINGS : ARMOR;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
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.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import slimeknights.tconstruct.library.client.armor.MaterialArmorModel;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.helper.ArmorUtil;
import slimeknights.tconstruct.library.tools.item.armor.texture.MaterialArmorTextureSupplier.MaterialSetCache;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Consumer;

/** Armor item for an item with multiple materials */
Expand All @@ -23,6 +26,12 @@ public FlexMaterialArmorItem(ArmorMaterial material, EquipmentSlot slot, Propert
this.cache = MaterialSetCache.FACTORY.apply(new ResourceLocation(material.getName()));
}

@Nullable
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return ArmorUtil.getDummyArmorTexture(slot);
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import slimeknights.tconstruct.library.client.armor.MultilayerArmorModel;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.helper.ArmorUtil;
import slimeknights.tconstruct.library.tools.item.armor.texture.ArmorTextureSupplier;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Consumer;

/** Armor model with two texture layers, the base and an overlay */
Expand All @@ -23,6 +26,12 @@ public FlexMultilayerArmorModel(ArmorMaterial material, EquipmentSlot slot, Prop
this.textures = textures;
}

@Nullable
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return ArmorUtil.getDummyArmorTexture(slot);
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
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 net.minecraftforge.client.extensions.common.IClientItemExtensions;
import slimeknights.tconstruct.library.tools.definition.ModifiableArmorMaterial;
import slimeknights.tconstruct.library.tools.helper.ArmorUtil;
import slimeknights.tconstruct.library.tools.item.armor.ModifiableArmorItem;
import slimeknights.tconstruct.library.tools.item.armor.texture.ArmorTextureSupplier;
import slimeknights.tconstruct.tools.client.SlimeskullArmorModel;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Consumer;

/** This item is mainly to return the proper model for a slimeskull */
Expand All @@ -22,6 +25,12 @@ public SlimeskullItem(ModifiableArmorMaterial material, Properties properties, A
this.helmet = helmet;
}

@Nullable
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return ArmorUtil.getDummyArmorTexture(slot);
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down

0 comments on commit 7c1d1d0

Please sign in to comment.