diff --git a/src/main/java/com/brokenkeyboard/leatheroverhaul/Events.java b/src/main/java/com/brokenkeyboard/leatheroverhaul/Events.java index c4c4cf8..9e292c7 100644 --- a/src/main/java/com/brokenkeyboard/leatheroverhaul/Events.java +++ b/src/main/java/com/brokenkeyboard/leatheroverhaul/Events.java @@ -8,6 +8,7 @@ import net.minecraft.world.item.DyeableLeatherItem; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RegisterColorHandlersEvent; +import net.minecraftforge.client.event.RegisterItemDecorationsEvent; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -57,5 +58,13 @@ public static class ClientEvents { public static void colorItems(RegisterColorHandlersEvent.Item event) { event.register((stack, value) -> value > 0 ? -1 : ((DyeableLeatherItem)stack.getItem()).getColor(stack), LeatherOverhaul.BUNDLE.get()); } + + @SubscribeEvent + public static void renderDurability(RegisterItemDecorationsEvent event) { + event.register(LeatherOverhaul.LEATHER_HELMET.get(), RenderDurability.INSTANCE); + event.register(LeatherOverhaul.LEATHER_CHESTPLATE.get(), RenderDurability.INSTANCE); + event.register(LeatherOverhaul.LEATHER_LEGGINGS.get(), RenderDurability.INSTANCE); + event.register(LeatherOverhaul.LEATHER_BOOTS.get(), RenderDurability.INSTANCE); + } } } \ No newline at end of file diff --git a/src/main/java/com/brokenkeyboard/leatheroverhaul/RenderDurability.java b/src/main/java/com/brokenkeyboard/leatheroverhaul/RenderDurability.java new file mode 100644 index 0000000..3fa04f2 --- /dev/null +++ b/src/main/java/com/brokenkeyboard/leatheroverhaul/RenderDurability.java @@ -0,0 +1,30 @@ +package com.brokenkeyboard.leatheroverhaul; + +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.client.IItemDecorator; + +import static com.brokenkeyboard.leatheroverhaul.item.LeatherArmor.getBonusArmor; +import static com.brokenkeyboard.leatheroverhaul.item.LeatherArmor.getBonusArmorMax; + +public class RenderDurability implements IItemDecorator { + + public static final RenderDurability INSTANCE = new RenderDurability(); + private static final int BAR_COLOR = Mth.color(0.4F, 0.4F, 1.0F); + + @Override + public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int xOffset, int yOffset) { + if (stack.getTag() != null && stack.getTag().contains("bonus_armor")) { + int barWidth = Math.min(1 + 12 * getBonusArmor(stack) / getBonusArmorMax(stack), 13); + int offset = stack.isDamaged() ? 0 : 2; + int xPos = xOffset + 2; + int yPos = yOffset + 11; + guiGraphics.fill(RenderType.guiOverlay(), xPos, yPos + offset, xPos + 13, yPos + 2 + offset, -16777216); + guiGraphics.fill(RenderType.guiOverlay(), xPos, yPos + offset, xPos + barWidth, yPos + 1 + offset, BAR_COLOR | -16777216); + } + return false; + } +} diff --git a/src/main/java/com/brokenkeyboard/leatheroverhaul/item/LeatherArmor.java b/src/main/java/com/brokenkeyboard/leatheroverhaul/item/LeatherArmor.java index da3fe98..7ef1a63 100644 --- a/src/main/java/com/brokenkeyboard/leatheroverhaul/item/LeatherArmor.java +++ b/src/main/java/com/brokenkeyboard/leatheroverhaul/item/LeatherArmor.java @@ -5,7 +5,6 @@ import com.google.common.collect.Multimap; import net.minecraft.Util; import net.minecraft.network.chat.Component; -import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; @@ -29,8 +28,6 @@ public class LeatherArmor extends DyeableArmorItem { - private static final int BAR_COLOR = Mth.color(0.4F, 0.4F, 1.0F); - private static final EnumMap ARMOR_UUID = Util.make(new EnumMap<>(ArmorItem.Type.class), (p_266744_) -> { p_266744_.put(ArmorItem.Type.BOOTS, UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B")); p_266744_.put(ArmorItem.Type.LEGGINGS, UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D")); @@ -81,28 +78,6 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List 0) - return true; - return super.isBarVisible(stack); - } - - @Override - public int getBarWidth(ItemStack stack) { - if (getBonusArmor(stack) > 0) { - return Math.min(1 + 12 * getBonusArmor(stack) / getBonusArmorMax(stack), 13); - } - return super.getBarWidth(stack); - } - - @Override - public int getBarColor(ItemStack stack) { - if (getBonusArmor(stack) > 0) - return BAR_COLOR; - return super.getBarColor(stack); - } - @Nullable @Override public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, @Nullable String type) {