mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Removed unused imports Add/remove all methods used for arrays Removed manual array copy
237 lines
6.1 KiB
Java
237 lines
6.1 KiB
Java
package mekanism.common.item;
|
|
|
|
import java.util.List;
|
|
|
|
import mekanism.api.EnumColor;
|
|
import mekanism.api.gas.Gas;
|
|
import mekanism.api.gas.GasStack;
|
|
import mekanism.api.gas.IGasItem;
|
|
import mekanism.client.render.ModelCustomArmor;
|
|
import mekanism.client.render.ModelCustomArmor.ArmorModel;
|
|
import mekanism.common.Mekanism;
|
|
import mekanism.common.MekanismFluids;
|
|
import mekanism.common.config.MekanismConfig.general;
|
|
import mekanism.common.util.ItemDataUtils;
|
|
import mekanism.common.util.LangUtils;
|
|
import net.minecraft.client.model.ModelBiped;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.init.SoundEvents;
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
import net.minecraft.item.ItemArmor;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.util.EnumHelper;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class ItemScubaTank extends ItemArmor implements IGasItem
|
|
{
|
|
public int TRANSFER_RATE = 16;
|
|
|
|
public ItemScubaTank()
|
|
{
|
|
super(EnumHelper.addArmorMaterial("SCUBATANK", "scubatank", 0, new int[] {0, 0, 0, 0}, 0, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0), 0, EntityEquipmentSlot.CHEST);
|
|
setCreativeTab(Mekanism.tabMekanism);
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag)
|
|
{
|
|
GasStack gasStack = getGas(itemstack);
|
|
|
|
if(gasStack == null)
|
|
{
|
|
list.add(LangUtils.localize("tooltip.noGas") + ".");
|
|
}
|
|
else {
|
|
list.add(LangUtils.localize("tooltip.stored") + " " + gasStack.getGas().getLocalizedName() + ": " + gasStack.amount);
|
|
}
|
|
|
|
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
|
|
public int getRGBDurabilityForDisplay(ItemStack stack)
|
|
{
|
|
return MathHelper.hsvToRGB(Math.max(0.0F, (float)(1-getDurabilityForDisplay(stack))) / 3.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidArmor(ItemStack stack, EntityEquipmentSlot armorType, Entity entity)
|
|
{
|
|
return armorType == EntityEquipmentSlot.CHEST;
|
|
}
|
|
|
|
@Override
|
|
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type)
|
|
{
|
|
return "mekanism:render/NullArmor.png";
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot armorSlot, ModelBiped _default)
|
|
{
|
|
ModelCustomArmor model = ModelCustomArmor.INSTANCE;
|
|
model.modelType = ArmorModel.SCUBATANK;
|
|
return model;
|
|
}
|
|
|
|
public void useGas(ItemStack itemstack)
|
|
{
|
|
setGas(itemstack, new GasStack(getGas(itemstack).getGas(), getGas(itemstack).amount-1));
|
|
}
|
|
|
|
public GasStack useGas(ItemStack itemstack, int amount)
|
|
{
|
|
if(getGas(itemstack) == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Gas type = getGas(itemstack).getGas();
|
|
|
|
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
|
|
setGas(itemstack, new GasStack(type, getStored(itemstack)-gasToUse));
|
|
|
|
return new GasStack(type, gasToUse);
|
|
}
|
|
|
|
@Override
|
|
public int getMaxGas(ItemStack itemstack)
|
|
{
|
|
return general.maxScubaGas;
|
|
}
|
|
|
|
@Override
|
|
public int getRate(ItemStack itemstack)
|
|
{
|
|
return TRANSFER_RATE;
|
|
}
|
|
|
|
@Override
|
|
public int addGas(ItemStack itemstack, GasStack stack)
|
|
{
|
|
if(getGas(itemstack) != null && getGas(itemstack).getGas() != stack.getGas())
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if(stack.getGas() != MekanismFluids.Oxygen)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
|
|
setGas(itemstack, new GasStack(stack.getGas(), getStored(itemstack)+toUse));
|
|
|
|
return toUse;
|
|
}
|
|
|
|
@Override
|
|
public GasStack removeGas(ItemStack itemstack, int amount)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public int getStored(ItemStack itemstack)
|
|
{
|
|
return getGas(itemstack) != null ? getGas(itemstack).amount : 0;
|
|
}
|
|
|
|
public void toggleFlowing(ItemStack stack)
|
|
{
|
|
setFlowing(stack, !getFlowing(stack));
|
|
}
|
|
|
|
public boolean getFlowing(ItemStack stack)
|
|
{
|
|
return ItemDataUtils.getBoolean(stack, "flowing");
|
|
}
|
|
|
|
public String getFlowingStr(ItemStack stack)
|
|
{
|
|
boolean flowing = getFlowing(stack);
|
|
|
|
return LangUtils.localize("tooltip." + (flowing ? "yes" : "no"));
|
|
}
|
|
|
|
public void setFlowing(ItemStack stack, boolean flowing)
|
|
{
|
|
ItemDataUtils.setBoolean(stack, "flowing", flowing);
|
|
}
|
|
|
|
@Override
|
|
public boolean canReceiveGas(ItemStack itemstack, Gas type)
|
|
{
|
|
return type == MekanismFluids.Oxygen;
|
|
}
|
|
|
|
@Override
|
|
public boolean canProvideGas(ItemStack itemstack, Gas type)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public GasStack getGas(ItemStack itemstack)
|
|
{
|
|
return GasStack.readFromNBT(ItemDataUtils.getCompound(itemstack, "stored"));
|
|
}
|
|
|
|
@Override
|
|
public void setGas(ItemStack itemstack, GasStack stack)
|
|
{
|
|
if(stack == null || stack.amount == 0)
|
|
{
|
|
ItemDataUtils.removeData(itemstack, "stored");
|
|
}
|
|
else {
|
|
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
|
|
GasStack gasStack = new GasStack(stack.getGas(), amount);
|
|
|
|
ItemDataUtils.setCompound(itemstack, "stored", gasStack.write(new NBTTagCompound()));
|
|
}
|
|
}
|
|
|
|
public ItemStack getEmptyItem()
|
|
{
|
|
ItemStack empty = new ItemStack(this);
|
|
setGas(empty, null);
|
|
|
|
return empty;
|
|
}
|
|
|
|
@Override
|
|
public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list)
|
|
{
|
|
if(!isInCreativeTab(tabs)) return;
|
|
ItemStack empty = new ItemStack(this);
|
|
setGas(empty, null);
|
|
list.add(empty);
|
|
|
|
ItemStack filled = new ItemStack(this);
|
|
setGas(filled, new GasStack(MekanismFluids.Oxygen, ((IGasItem)filled.getItem()).getMaxGas(filled)));
|
|
list.add(filled);
|
|
}
|
|
}
|