2014-04-04 03:34:33 +02:00
|
|
|
package mekanism.api;
|
|
|
|
|
|
|
|
import mekanism.api.gas.GasStack;
|
|
|
|
import mekanism.api.gas.GasTank;
|
|
|
|
import mekanism.common.util.StackUtils;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTank;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An input of a gas, a fluid and an item for the pressurized reaction chamber
|
|
|
|
*/
|
|
|
|
public class PressurizedReactants
|
|
|
|
{
|
|
|
|
private ItemStack theSolid;
|
|
|
|
private FluidStack theFluid;
|
|
|
|
private GasStack theGas;
|
|
|
|
|
|
|
|
public PressurizedReactants(ItemStack solid, FluidStack fluid, GasStack gas)
|
|
|
|
{
|
|
|
|
theSolid = solid;
|
|
|
|
theFluid = fluid;
|
|
|
|
theGas = gas;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is a valid PressurizedReactants
|
|
|
|
*/
|
|
|
|
public boolean isValid()
|
|
|
|
{
|
|
|
|
return theSolid != null && theFluid != null && theGas != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the needed amount of gas from each tank.
|
|
|
|
* @param item - ItemStack to draw from
|
|
|
|
* @param fluidTank - fluid tank to draw from
|
|
|
|
* @param gasTank - gas tank to draw from
|
|
|
|
*/
|
|
|
|
public void use(ItemStack item, FluidTank fluidTank, GasTank gasTank)
|
|
|
|
{
|
|
|
|
if(meets(new PressurizedReactants(item, fluidTank.getFluid(), gasTank.getGas())))
|
|
|
|
{
|
|
|
|
item.stackSize -= theSolid.stackSize;
|
|
|
|
fluidTank.drain(theFluid.amount, true);
|
|
|
|
gasTank.draw(theGas.amount, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not this PressurizedReactants's ItemStack entry's item type is equal to the item type of the given item.
|
|
|
|
* @param stack - stack to check
|
|
|
|
* @return if the stack's item type is contained in this PressurizedReactants
|
|
|
|
*/
|
|
|
|
public boolean containsType(ItemStack stack)
|
|
|
|
{
|
|
|
|
if(stack == null || stack.stackSize == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return StackUtils.equalsWildcard(stack, theSolid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not this PressurizedReactants's FluidStack entry's fluid type is equal to the fluid type of the given fluid.
|
|
|
|
* @param stack - stack to check
|
|
|
|
* @return if the stack's fluid type is contained in this PressurizedReactants
|
|
|
|
*/
|
|
|
|
public boolean containsType(FluidStack stack)
|
|
|
|
{
|
|
|
|
if(stack == null || stack.amount == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack.isFluidEqual(theFluid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not this PressurizedReactants's GasStack entry's gas type is equal to the gas type of the given gas.
|
|
|
|
* @param stack - stack to check
|
|
|
|
* @return if the stack's gas type is contained in this PressurizedReactants
|
|
|
|
*/
|
|
|
|
public boolean containsType(GasStack stack)
|
|
|
|
{
|
|
|
|
if(stack == null || stack.amount == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack.isGasEqual(theGas);
|
|
|
|
}
|
|
|
|
|
2014-04-06 02:16:09 +02:00
|
|
|
public boolean meetsInput(ItemStack itemStack, FluidStack fluidStack, GasStack gasStack)
|
|
|
|
{
|
|
|
|
return meets(new PressurizedReactants(itemStack, fluidStack, gasStack));
|
|
|
|
}
|
|
|
|
|
2014-04-04 03:34:33 +02:00
|
|
|
/**
|
|
|
|
* Actual implementation of meetsInput(), performs the checks.
|
|
|
|
* @param input - input to check
|
|
|
|
* @return if the input meets this input's requirements
|
|
|
|
*/
|
|
|
|
private boolean meets(PressurizedReactants input)
|
|
|
|
{
|
|
|
|
if(input == null || !input.isValid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-06 02:16:09 +02:00
|
|
|
if(!(StackUtils.equalsWildcard(input.theSolid, theSolid) && input.theFluid.isFluidEqual(theFluid) && input.theGas.isGasEqual(theGas)))
|
2014-04-04 03:34:33 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return input.theSolid.stackSize >= theSolid.stackSize && input.theFluid.amount >= theFluid.amount && input.theGas.amount >= theGas.amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PressurizedReactants copy()
|
|
|
|
{
|
2014-04-06 02:16:09 +02:00
|
|
|
return new PressurizedReactants(theSolid.copy(), theFluid.copy(), theGas.copy());
|
2014-04-04 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|