Use Forge handlers for jetpack/scuba tank display bar instead of item damage

This commit is contained in:
aidancbrady 2016-02-20 11:07:54 -05:00
parent 279cccaa9b
commit 0f59e722e1
2 changed files with 28 additions and 34 deletions

View file

@ -37,14 +37,24 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor
{ {
super(EnumHelper.addArmorMaterial("JETPACK", 0, new int[] {0, 0, 0, 0}, 0), 0, 1); super(EnumHelper.addArmorMaterial("JETPACK", 0, new int[] {0, 0, 0, 0}, 0), 0, 1);
setCreativeTab(Mekanism.tabMekanism); setCreativeTab(Mekanism.tabMekanism);
setMaxDamage(100);
setNoRepair();
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister register) {} public void registerIcons(IIconRegister register) {}
@Override
public boolean showDurabilityBar(ItemStack stack)
{
return true;
}
@Override
public double getDurabilityForDisplay(ItemStack stack)
{
return 1D-((getGas(stack) != null ? (double)getGas(stack).amount : 0D)/(double)getMaxGas(stack));
}
@Override @Override
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{ {
@ -163,17 +173,7 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor
return null; return null;
} }
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored")); return GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
} }
@Override @Override
@ -212,14 +212,12 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor
if(stack == null || stack.amount == 0) if(stack == null || stack.amount == 0)
{ {
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored"); itemstack.stackTagCompound.removeTag("stored");
} }
else { else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack))); int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount); GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setTag("stored", gasStack.write(new NBTTagCompound())); itemstack.stackTagCompound.setTag("stored", gasStack.write(new NBTTagCompound()));
} }
} }
@ -228,7 +226,7 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor
{ {
ItemStack empty = new ItemStack(this); ItemStack empty = new ItemStack(this);
setGas(empty, null); setGas(empty, null);
empty.setItemDamage(100);
return empty; return empty;
} }
@ -237,7 +235,6 @@ public class ItemJetpack extends ItemArmor implements IGasItem, ISpecialArmor
{ {
ItemStack empty = new ItemStack(this); ItemStack empty = new ItemStack(this);
setGas(empty, null); setGas(empty, null);
empty.setItemDamage(100);
list.add(empty); list.add(empty);
ItemStack filled = new ItemStack(this); ItemStack filled = new ItemStack(this);

View file

@ -34,8 +34,6 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
{ {
super(EnumHelper.addArmorMaterial("SCUBATANK", 0, new int[] {0, 0, 0, 0}, 0), 0, 1); super(EnumHelper.addArmorMaterial("SCUBATANK", 0, new int[] {0, 0, 0, 0}, 0), 0, 1);
setCreativeTab(Mekanism.tabMekanism); setCreativeTab(Mekanism.tabMekanism);
setMaxDamage(100);
setNoRepair();
} }
@Override @Override
@ -54,6 +52,18 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
list.add(EnumColor.GREY + LangUtils.localize("tooltip.flowing") + ": " + (getFlowing(itemstack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + getFlowingStr(itemstack)); list.add(EnumColor.GREY + LangUtils.localize("tooltip.flowing") + ": " + (getFlowing(itemstack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + getFlowingStr(itemstack));
} }
@Override
public boolean showDurabilityBar(ItemStack stack)
{
return true;
}
@Override
public double getDurabilityForDisplay(ItemStack stack)
{
return 1D-((getGas(stack) != null ? (double)getGas(stack).amount : 0D)/(double)getMaxGas(stack));
}
@Override @Override
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity) public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
{ {
@ -189,17 +199,7 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
return null; return null;
} }
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored")); return GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
} }
@Override @Override
@ -212,14 +212,12 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
if(stack == null || stack.amount == 0) if(stack == null || stack.amount == 0)
{ {
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored"); itemstack.stackTagCompound.removeTag("stored");
} }
else { else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack))); int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount); GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setTag("stored", gasStack.write(new NBTTagCompound())); itemstack.stackTagCompound.setTag("stored", gasStack.write(new NBTTagCompound()));
} }
} }
@ -234,7 +232,7 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
{ {
ItemStack empty = new ItemStack(this); ItemStack empty = new ItemStack(this);
setGas(empty, null); setGas(empty, null);
empty.setItemDamage(100);
return empty; return empty;
} }
@ -243,7 +241,6 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
{ {
ItemStack empty = new ItemStack(this); ItemStack empty = new ItemStack(this);
setGas(empty, null); setGas(empty, null);
empty.setItemDamage(100);
list.add(empty); list.add(empty);
ItemStack filled = new ItemStack(this); ItemStack filled = new ItemStack(this);