Made the Chest have Air instead of the Helm

This commit is contained in:
Ellpeck 2015-07-11 13:52:20 +02:00
parent ac46458220
commit 824a86b816

View file

@ -9,14 +9,16 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
public class ItemScubaArmor extends ItemArmorAA{ public class ItemScubaArmor extends ItemArmorAA{
private static final int helmetTime = 500; private static final int chestAirTime = 500;
private static final int helmetTimeDecreaseInAir = 3; private static final int chestAirIncreasePerTick = 3;
public ItemScubaArmor(String name, int type){ public ItemScubaArmor(String name, int type){
super(name, InitArmorMaterials.armorMaterialScuba, type, null, "armorScuba"); super(name, InitArmorMaterials.armorMaterialScuba, type, null, "armorScuba");
@ -25,29 +27,35 @@ public class ItemScubaArmor extends ItemArmorAA{
@Override @Override
public void onArmorTick(World world, EntityPlayer player, ItemStack armor){ public void onArmorTick(World world, EntityPlayer player, ItemStack armor){
if(!world.isRemote){ if(!world.isRemote){
if(armor.getItem() == InitItems.itemScubaHelm){ if(this.hasFullArmor(player)){
NBTTagCompound compound = armor.getTagCompound(); NBTTagCompound compound = armor.getTagCompound();
if(compound == null) compound = new NBTTagCompound(); if(compound == null) compound = new NBTTagCompound();
if(armor.getItem() == InitItems.itemScubaChest){
if(player.isInsideOfMaterial(Material.water)){ if(player.isInsideOfMaterial(Material.water)){
int time = compound.getInteger("waitTime"); int time = compound.getInteger("waitTime");
if(time < helmetTime){ if(time < chestAirTime){
compound.setInteger("waitTime", time+1); compound.setInteger("waitTime", time+1);
player.setAir(300); player.addPotionEffect(new PotionEffect(Potion.waterBreathing.getId(), 1, 0));
} }
} }
else{ else{
this.addAir(compound); this.addAirToChest(compound);
}
} }
armor.setTagCompound(compound); armor.setTagCompound(compound);
} }
} }
} }
private void addAir(NBTTagCompound compound){ private boolean hasFullArmor(EntityPlayer player){
return player.inventory.getStackInSlot(36) != null && player.inventory.getStackInSlot(37) != null && player.inventory.getStackInSlot(38) != null && player.inventory.getStackInSlot(39) != null && player.inventory.getStackInSlot(36).getItem() == InitItems.itemScubaBoots && player.inventory.getStackInSlot(37).getItem() == InitItems.itemScubaPants && player.inventory.getStackInSlot(38).getItem() == InitItems.itemScubaChest && player.inventory.getStackInSlot(39).getItem() == InitItems.itemScubaHelm;
}
private void addAirToChest(NBTTagCompound compound){
int time = compound.getInteger("waitTime"); int time = compound.getInteger("waitTime");
if(time > 0){ if(time > 0){
compound.setInteger("waitTime", time < helmetTimeDecreaseInAir ? 0 : time-helmetTimeDecreaseInAir); compound.setInteger("waitTime", time < chestAirIncreasePerTick ? 0 : time-chestAirIncreasePerTick);
} }
} }
@ -56,7 +64,7 @@ public class ItemScubaArmor extends ItemArmorAA{
if(!entity.isInsideOfMaterial(Material.water)){ if(!entity.isInsideOfMaterial(Material.water)){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
if(compound != null){ if(compound != null){
this.addAir(compound); this.addAirToChest(compound);
} }
} }
} }
@ -66,10 +74,10 @@ public class ItemScubaArmor extends ItemArmorAA{
@SideOnly(Side.CLIENT) @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){
super.addInformation(stack, player, list, isHeld); super.addInformation(stack, player, list, isHeld);
if(KeyUtil.isShiftPressed() && stack.getItem() == InitItems.itemScubaHelm){ if(KeyUtil.isShiftPressed() && stack.getItem() == InitItems.itemScubaChest){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
//TODO Localize //TODO Localize
list.add("Air: "+(compound == null ? helmetTime : helmetTime-compound.getInteger("waitTime"))+"/"+helmetTime); list.add("Air: "+(compound == null ? chestAirTime : chestAirTime-compound.getInteger("waitTime"))+"/"+chestAirTime);
} }
} }
} }