Mekanism-tilera-Edition/common/mekanism/api/gas/Gas.java

112 lines
1.6 KiB
Java
Raw Normal View History

package mekanism.api.gas;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
public class Gas
{
private String name;
private String unlocalizedName;
private Fluid fluid;
private Icon icon;
public Gas(String s)
{
unlocalizedName = name = s;
}
public String getName()
{
return name;
}
public String getUnlocalizedName()
{
return "gas." + unlocalizedName;
}
public String getLocalizedName()
{
return StatCollector.translateToLocal(getUnlocalizedName());
}
public Gas setUnlocalizedName(String s)
{
unlocalizedName = s;
return this;
}
public Icon getIcon()
{
return icon;
}
public Gas setIcon(Icon i)
{
icon = i;
if(hasFluid())
{
fluid.setIcons(getIcon());
}
return this;
}
public int getID()
{
return GasRegistry.getGasID(this);
}
public NBTTagCompound write(NBTTagCompound nbtTags)
{
2013-11-30 17:31:18 +01:00
nbtTags.setString("gasName", getName());
return nbtTags;
}
public static Gas readFromNBT(NBTTagCompound nbtTags)
{
if(nbtTags == null || nbtTags.hasNoTags())
{
return null;
}
2013-11-30 17:31:18 +01:00
return GasRegistry.getGas(nbtTags.getString("gasName"));
}
public boolean hasFluid()
{
return fluid != null;
}
public Fluid getFluid()
{
return fluid;
}
2013-11-27 19:24:13 +01:00
public Gas registerFluid()
{
if(fluid == null)
{
fluid = new Fluid(getName()).setGaseous(true);
FluidRegistry.registerFluid(fluid);
}
2013-11-27 19:24:13 +01:00
return this;
}
@Override
public String toString()
{
return name;
}
}