Fix durability bars

This commit is contained in:
Nicholas Ignoffo 2017-01-02 02:28:02 -08:00
parent e845332846
commit 11fe41c654
2 changed files with 25 additions and 3 deletions

View file

@ -14,6 +14,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -72,7 +73,7 @@ public class ItemInscriptionTool extends ItemBindableBase implements IVariantPro
{ {
stack.getTagCompound().setInteger(Constants.NBT.USES, --uses); stack.getTagCompound().setInteger(Constants.NBT.USES, --uses);
if (uses <= 0) if (uses <= 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null); player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
} }
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
@ -83,18 +84,25 @@ public class ItemInscriptionTool extends ItemBindableBase implements IVariantPro
@Override @Override
public boolean showDurabilityBar(ItemStack stack) public boolean showDurabilityBar(ItemStack stack)
{ {
return true; return stack.hasTagCompound();
} }
@Override @Override
public double getDurabilityForDisplay(ItemStack stack) public double getDurabilityForDisplay(ItemStack stack)
{ {
stack = NBTHelper.checkNBT(stack);
int uses = stack.getTagCompound().getInteger(Constants.NBT.USES); int uses = stack.getTagCompound().getInteger(Constants.NBT.USES);
return 1.0 - ((double) uses / (double) 10); return 1.0 - ((double) uses / (double) 10);
} }
@Override
public int getRGBDurabilityForDisplay(ItemStack stack)
{
int uses = stack.getTagCompound().getInteger(Constants.NBT.USES);
return MathHelper.hsvToRGB(Math.max(0.0F, (float)(uses) / 10) / 3.0F, 1.0F, 1.0F);
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced) public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced)

View file

@ -13,6 +13,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -145,6 +146,19 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IMeshProvider, I
return 1.0 - (getWill(type, stack) / maxWill); return 1.0 - (getWill(type, stack) / maxWill);
} }
@Override
public int getRGBDurabilityForDisplay(ItemStack stack)
{
EnumDemonWillType type = this.getCurrentType(stack);
double maxWill = getMaxWill(type, stack);
if (maxWill <= 0)
{
return 1;
}
return MathHelper.hsvToRGB(Math.max(0.0F, (float)(getWill(type, stack)) / (float) maxWill) / 3.0F, 1.0F, 1.0F);
}
@Override @Override
public ItemStack fillDemonWillGem(ItemStack soulGemStack, ItemStack soulStack) public ItemStack fillDemonWillGem(ItemStack soulGemStack, ItemStack soulStack)
{ {