fixed durabilitybar not rendering correctly
@@ -5,6 +5,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Multimap;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
+import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
@@ -210,6 +211,18 @@ public abstract class ModularItem extends TetraItem implements IModularItem, ITo
return Math.min(stack.getMaxDamage() - stack.getDamageValue() - 1, amount);
}
+ @Override
+ public int getBarWidth(ItemStack itemStack) {
+ return Math.round(13.0F - (float)itemStack.getDamageValue() * 13.0F / (float) getMaxDamage(itemStack));
+ }
+
+ @Override
+ public int getBarColor(ItemStack itemStack) {
+ float maxDamage = getMaxDamage(itemStack);
+ float f = Math.max(0.0F, (maxDamage - itemStack.getDamageValue()) / maxDamage);
+ return Mth.hsvToRgb(f / 3.0F, 1.0F, 1.0F);
+ }
+
@Override
public void onCraftedBy(ItemStack itemStack, Level world, Player player) {
IModularItem.updateIdentifier(itemStack);
