2013-11-27 02:11:26 +01:00
|
|
|
package mekanism.api.gas;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-11-29 03:43:53 +01:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
|
2013-11-27 02:11:26 +01:00
|
|
|
public class GasRegistry
|
|
|
|
{
|
|
|
|
private static ArrayList<Gas> registeredGasses = new ArrayList<Gas>();
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Register a new gas into GasRegistry.
|
|
|
|
* @param gas - Gas to register
|
|
|
|
* @return the gas that has been registered, pulled right out of GasRegistry
|
|
|
|
*/
|
2013-11-29 03:43:53 +01:00
|
|
|
public static Gas register(Gas gas)
|
2013-11-27 02:11:26 +01:00
|
|
|
{
|
2013-11-29 03:43:53 +01:00
|
|
|
if(gas == null)
|
2013-11-27 02:11:26 +01:00
|
|
|
{
|
2013-11-29 03:43:53 +01:00
|
|
|
return null;
|
2013-11-27 02:11:26 +01:00
|
|
|
}
|
2013-11-29 03:43:53 +01:00
|
|
|
|
2013-11-27 02:11:26 +01:00
|
|
|
registeredGasses.add(gas);
|
2013-11-29 03:43:53 +01:00
|
|
|
|
|
|
|
return getGas(gas.getName());
|
2013-11-27 02:11:26 +01:00
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Gets the gas associated with the defined ID.
|
|
|
|
* @param id - ID to check
|
|
|
|
* @return gas associated with defined ID
|
|
|
|
*/
|
2013-11-27 02:11:26 +01:00
|
|
|
public static Gas getGas(int id)
|
|
|
|
{
|
|
|
|
if(id == -1)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return registeredGasses.get(id);
|
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Gets the gas associated with the defined fluid.
|
|
|
|
* @param f - fluid to check
|
|
|
|
* @return the gas associated with the fluid
|
|
|
|
*/
|
2013-11-29 03:43:53 +01:00
|
|
|
public static Gas getGas(Fluid f)
|
|
|
|
{
|
|
|
|
for(Gas gas : getRegisteredGasses())
|
|
|
|
{
|
|
|
|
if(gas.hasFluid() && gas.getFluid() == f)
|
|
|
|
{
|
|
|
|
return gas;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Whether or not GasRegistry contains a gas with the specified name
|
|
|
|
* @param name - name to check
|
|
|
|
* @return if GasRegistry contains a gas with the defined name
|
|
|
|
*/
|
2013-11-27 02:11:26 +01:00
|
|
|
public static boolean containsGas(String name)
|
|
|
|
{
|
|
|
|
return getGas(name) != null;
|
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Gets the list of all gasses registered in GasRegistry.
|
|
|
|
* @return a cloned list of all registered gasses
|
|
|
|
*/
|
2013-11-27 02:11:26 +01:00
|
|
|
public static List<Gas> getRegisteredGasses()
|
|
|
|
{
|
|
|
|
return (List<Gas>)registeredGasses.clone();
|
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Gets the gas associated with the specified name.
|
|
|
|
* @param name - name of the gas to get
|
|
|
|
* @return gas associated with the name
|
|
|
|
*/
|
2013-11-27 02:11:26 +01:00
|
|
|
public static Gas getGas(String name)
|
|
|
|
{
|
|
|
|
for(Gas gas : registeredGasses)
|
|
|
|
{
|
2013-12-13 02:35:37 +01:00
|
|
|
if(gas.getName().toLowerCase().equals(name.toLowerCase()))
|
2013-11-27 02:11:26 +01:00
|
|
|
{
|
|
|
|
return gas;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
/**
|
|
|
|
* Gets the gas ID of a specified gas.
|
|
|
|
* @param gas - gas to get the ID from
|
|
|
|
* @return gas ID
|
|
|
|
*/
|
2013-11-27 02:11:26 +01:00
|
|
|
public static int getGasID(Gas gas)
|
|
|
|
{
|
|
|
|
if(gas == null || !containsGas(gas.getName()))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return registeredGasses.indexOf(gas);
|
|
|
|
}
|
|
|
|
}
|