Skip to content

Commit

Permalink
Add separate bonus durability bar
Browse files Browse the repository at this point in the history
  • Loading branch information
BrokenK3yboard committed Jan 6, 2024
1 parent 81c5544 commit 3b5f3e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/brokenkeyboard/leatheroverhaul/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ArmorItem.Type, UUID> 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"));
Expand Down Expand Up @@ -81,28 +78,6 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List<Compone
displayPotionEffect(stack, components);
}

@Override
public boolean isBarVisible(ItemStack stack) {
if (getBonusArmor(stack) > 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) {
Expand Down

0 comments on commit 3b5f3e1

Please sign in to comment.