From ac464582204dee73c5d06f9d8360bc1b1226de68 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 11 Jul 2015 07:08:09 +0200 Subject: [PATCH] Made the Scuba Helmet recharge when not in Armor Slot --- .../actuallyadditions/items/ItemArmorAA.java | 2 +- .../items/ItemScubaArmor.java | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemArmorAA.java b/src/main/java/ellpeck/actuallyadditions/items/ItemArmorAA.java index b01db223f..7a0e9bc1c 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemArmorAA.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemArmorAA.java @@ -42,7 +42,7 @@ public class ItemArmorAA extends ItemArmor implements INameableItem{ @Override @SuppressWarnings("unchecked") @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) { + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){ ItemUtil.addInformation(this, list, 1, ""); } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemScubaArmor.java b/src/main/java/ellpeck/actuallyadditions/items/ItemScubaArmor.java index 575fea0e0..2516ec691 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemScubaArmor.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemScubaArmor.java @@ -3,9 +3,9 @@ package ellpeck.actuallyadditions.items; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.material.InitArmorMaterials; -import ellpeck.actuallyadditions.util.ItemUtil; import ellpeck.actuallyadditions.util.KeyUtil; import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -29,28 +29,43 @@ public class ItemScubaArmor extends ItemArmorAA{ NBTTagCompound compound = armor.getTagCompound(); if(compound == null) compound = new NBTTagCompound(); - int time = compound.getInteger("waitTime"); if(player.isInsideOfMaterial(Material.water)){ + int time = compound.getInteger("waitTime"); if(time < helmetTime){ compound.setInteger("waitTime", time+1); player.setAir(300); } } else{ - if(time > 0){ - compound.setInteger("waitTime", time < helmetTimeDecreaseInAir ? 0 : time-helmetTimeDecreaseInAir); - } + this.addAir(compound); } armor.setTagCompound(compound); } } } + private void addAir(NBTTagCompound compound){ + int time = compound.getInteger("waitTime"); + if(time > 0){ + compound.setInteger("waitTime", time < helmetTimeDecreaseInAir ? 0 : time-helmetTimeDecreaseInAir); + } + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){ + if(!entity.isInsideOfMaterial(Material.water)){ + NBTTagCompound compound = stack.getTagCompound(); + if(compound != null){ + this.addAir(compound); + } + } + } + @Override @SuppressWarnings("unchecked") @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) { - ItemUtil.addInformation(this, list, 1, ""); + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){ + super.addInformation(stack, player, list, isHeld); if(KeyUtil.isShiftPressed() && stack.getItem() == InitItems.itemScubaHelm){ NBTTagCompound compound = stack.getTagCompound(); //TODO Localize