mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
81 lines
1.8 KiB
Java
81 lines
1.8 KiB
Java
package mekanism.common.recipe.inputs;
|
|
|
|
import mekanism.api.infuse.InfuseType;
|
|
import mekanism.api.util.StackUtils;
|
|
import mekanism.common.InfuseStorage;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
/**
|
|
* An infusion input, containing the type of and amount of infuse the operation requires, as well as the input ItemStack.
|
|
* @author AidanBrady
|
|
*
|
|
*/
|
|
public class InfusionInput extends MachineInput<InfusionInput>
|
|
{
|
|
public InfuseStorage infuse;
|
|
|
|
/** The input ItemStack */
|
|
public ItemStack inputStack;
|
|
|
|
public InfusionInput(InfuseStorage storage, ItemStack itemStack)
|
|
{
|
|
infuse = new InfuseStorage(storage.type, storage.amount);
|
|
inputStack = itemStack;
|
|
}
|
|
|
|
public InfusionInput(InfuseType infusionType, int required, ItemStack itemStack)
|
|
{
|
|
infuse = new InfuseStorage(infusionType, required);
|
|
inputStack = itemStack;
|
|
}
|
|
|
|
@Override
|
|
public InfusionInput copy()
|
|
{
|
|
return new InfusionInput(infuse.type, infuse.amount, inputStack.copy());
|
|
}
|
|
|
|
@Override
|
|
public boolean isValid()
|
|
{
|
|
return infuse.type != null && inputStack != null;
|
|
}
|
|
|
|
public boolean use(ItemStack[] inventory, int index, InfuseStorage infuseStorage, boolean deplete)
|
|
{
|
|
if(StackUtils.contains(inventory[index], inputStack) && infuseStorage.contains(infuse))
|
|
{
|
|
if(deplete)
|
|
{
|
|
inventory[index] = StackUtils.subtract(inventory[index], inputStack);
|
|
infuseStorage.subtract(infuse);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int hashIngredients()
|
|
{
|
|
return infuse.type.unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack);
|
|
}
|
|
|
|
@Override
|
|
public boolean testEquality(InfusionInput other)
|
|
{
|
|
if(!isValid())
|
|
{
|
|
return !other.isValid();
|
|
}
|
|
return infuse.type == other.infuse.type && StackUtils.equalsWildcardWithNBT(inputStack, other.inputStack);
|
|
}
|
|
|
|
@Override
|
|
public boolean isInstance(Object other)
|
|
{
|
|
return other instanceof InfusionInput;
|
|
}
|
|
}
|