mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 19:59:55 +00:00
Make Ammo stuff more resilient against corrupt tools with no nbt
This commit is contained in:
1 parent
9f64ef46e8
commit
4027392d67
1 file changed
+5
-1
@@ -22,12 +22,14 @@ public abstract class AmmoItem extends ToolCore implements IAmmo {
|
||||
|
||||
@Override
|
||||
public int getAmmoCount(ItemStack stack) {
|
||||
if(!stack.hasTagCompound()) return 0;
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return tags.getInteger("Ammo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmmo(ItemStack stack) {
|
||||
if(!stack.hasTagCompound()) return 0;
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
return getMaxAmmo(tags);
|
||||
}
|
||||
@@ -40,6 +42,7 @@ public abstract class AmmoItem extends ToolCore implements IAmmo {
|
||||
|
||||
@Override
|
||||
public int addAmmo(int toAdd, ItemStack stack) {
|
||||
if(!stack.hasTagCompound()) return toAdd;
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int oldCount = tags.getInteger("Ammo");
|
||||
int newCount = Math.min(oldCount + toAdd, getMaxAmmo(stack));
|
||||
@@ -49,6 +52,7 @@ public abstract class AmmoItem extends ToolCore implements IAmmo {
|
||||
|
||||
@Override
|
||||
public int consumeAmmo(int toUse, ItemStack stack) {
|
||||
if(!stack.hasTagCompound()) return toUse;
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int oldCount = tags.getInteger("Ammo");
|
||||
int newCount = Math.max(oldCount - toUse, 0);
|
||||
@@ -60,7 +64,7 @@ public abstract class AmmoItem extends ToolCore implements IAmmo {
|
||||
|
||||
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player)
|
||||
{
|
||||
if(stack.getItem() == null || !(stack.getItem() instanceof IAmmo))
|
||||
if(stack.getItem() == null || !stack.hasTagCompound() || !(stack.getItem() instanceof IAmmo))
|
||||
return false;
|
||||
|
||||
// check if our candidate fits
|
||||
|
||||
Reference in new issue
Block a user