Allow any input or output to be null, includes a fix for the grinder fluid as well
This commit is contained in:
parent
46ee2fc71d
commit
2d17902d03
29 changed files with 1208 additions and 1266 deletions
|
@ -1,67 +1,67 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extend this to add a recipe
|
||||
*/
|
||||
public abstract class BaseRecipe implements IBaseRecipeType {
|
||||
|
||||
public ArrayList<ItemStack> inputs;
|
||||
public ArrayList<ItemStack> inputs;
|
||||
|
||||
public ArrayList<ItemStack> outputs;
|
||||
public ArrayList<ItemStack> outputs;
|
||||
|
||||
public String name;
|
||||
public String name;
|
||||
|
||||
public int tickTime;
|
||||
public int tickTime;
|
||||
|
||||
public int euPerTick;
|
||||
public int euPerTick;
|
||||
|
||||
public BaseRecipe(String name, int tickTime, int euPerTick) {
|
||||
inputs = new ArrayList<ItemStack>();
|
||||
outputs = new ArrayList<ItemStack>();
|
||||
this.name = name;
|
||||
//This adds all new recipes
|
||||
this.tickTime = tickTime;
|
||||
this.euPerTick = euPerTick;
|
||||
}
|
||||
public BaseRecipe(String name, int tickTime, int euPerTick) {
|
||||
inputs = new ArrayList<ItemStack>();
|
||||
outputs = new ArrayList<ItemStack>();
|
||||
this.name = name;
|
||||
//This adds all new recipes
|
||||
this.tickTime = tickTime;
|
||||
this.euPerTick = euPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
@Override
|
||||
public List<ItemStack> getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
@Override
|
||||
public List<ItemStack> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getRecipeName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tickTime() {
|
||||
return tickTime;
|
||||
}
|
||||
@Override
|
||||
public int tickTime() {
|
||||
return tickTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int euPerTick() {
|
||||
return euPerTick;
|
||||
}
|
||||
@Override
|
||||
public int euPerTick() {
|
||||
return euPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraft(TileEntity tile) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canCraft(TileEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCraft(TileEntity tile) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCraft(TileEntity tile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the base recipe class implement this to make a recipe handler
|
||||
*/
|
||||
public interface IBaseRecipeType {
|
||||
|
||||
/**
|
||||
* Use this to get all of the inputs
|
||||
*
|
||||
* @return the List of inputs
|
||||
*/
|
||||
public List<ItemStack> getInputs();
|
||||
/**
|
||||
* Use this to get all of the inputs
|
||||
*
|
||||
* @return the List of inputs
|
||||
*/
|
||||
public List<ItemStack> getInputs();
|
||||
|
||||
/**
|
||||
* Use this to get all of the outputs
|
||||
*
|
||||
* @return the List of outputs
|
||||
*/
|
||||
public List<ItemStack> getOutputs();
|
||||
/**
|
||||
* Use this to get all of the outputs
|
||||
*
|
||||
* @return the List of outputs
|
||||
*/
|
||||
public List<ItemStack> getOutputs();
|
||||
|
||||
/**
|
||||
* This is the name to check that the recipe is the one that should be used in
|
||||
* the tile entity that is set up to process this recipe.
|
||||
*
|
||||
* @return The recipeName
|
||||
*/
|
||||
public String getRecipeName();
|
||||
/**
|
||||
* This is the name to check that the recipe is the one that should be used in
|
||||
* the tile entity that is set up to process this recipe.
|
||||
*
|
||||
* @return The recipeName
|
||||
*/
|
||||
public String getRecipeName();
|
||||
|
||||
/**
|
||||
* This is how long the recipe needs to tick for the crafting operation to complete
|
||||
* @return tick length
|
||||
*/
|
||||
public int tickTime();
|
||||
/**
|
||||
* This is how long the recipe needs to tick for the crafting operation to complete
|
||||
*
|
||||
* @return tick length
|
||||
*/
|
||||
public int tickTime();
|
||||
|
||||
/**
|
||||
* This is how much eu Per tick the machine should use
|
||||
* @return the amount of eu to be used per tick.
|
||||
*/
|
||||
public int euPerTick();
|
||||
/**
|
||||
* This is how much eu Per tick the machine should use
|
||||
*
|
||||
* @return the amount of eu to be used per tick.
|
||||
*/
|
||||
public int euPerTick();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tile the tile that is doing the crafting
|
||||
* @return if true the recipe will craft, if false it will not
|
||||
*/
|
||||
public boolean canCraft(TileEntity tile);
|
||||
/**
|
||||
* @param tile the tile that is doing the crafting
|
||||
* @return if true the recipe will craft, if false it will not
|
||||
*/
|
||||
public boolean canCraft(TileEntity tile);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tile the tile that is doing the crafting
|
||||
* @return return true if fluid was taken and should craft
|
||||
*/
|
||||
public boolean onCraft(TileEntity tile);
|
||||
/**
|
||||
* @param tile the tile that is doing the crafting
|
||||
* @return return true if fluid was taken and should craft
|
||||
*/
|
||||
public boolean onCraft(TileEntity tile);
|
||||
}
|
||||
|
|
|
@ -1,248 +1,246 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.ItemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Use this in your tile entity to craft things
|
||||
*/
|
||||
public class RecipeCrafter {
|
||||
|
||||
/**
|
||||
* This is the recipe type to use
|
||||
*/
|
||||
public String recipeName;
|
||||
/**
|
||||
* This is the recipe type to use
|
||||
*/
|
||||
public String recipeName;
|
||||
|
||||
/**
|
||||
* This is the parent tile
|
||||
*/
|
||||
public TileMachineBase parentTile;
|
||||
/**
|
||||
* This is the parent tile
|
||||
*/
|
||||
public TileMachineBase parentTile;
|
||||
|
||||
/**
|
||||
* This is the place to use the power from
|
||||
*/
|
||||
public BasicSink energy;
|
||||
/**
|
||||
* This is the place to use the power from
|
||||
*/
|
||||
public BasicSink energy;
|
||||
|
||||
/**
|
||||
* This is the amount of inputs that the setRecipe has
|
||||
*/
|
||||
public int inputs;
|
||||
/**
|
||||
* This is the amount of inputs that the setRecipe has
|
||||
*/
|
||||
public int inputs;
|
||||
|
||||
/**
|
||||
* This is the amount of outputs that the recipe has
|
||||
*/
|
||||
public int outputs;
|
||||
/**
|
||||
* This is the amount of outputs that the recipe has
|
||||
*/
|
||||
public int outputs;
|
||||
|
||||
/**
|
||||
* This is the inventory to use for the crafting
|
||||
*/
|
||||
public Inventory inventory;
|
||||
/**
|
||||
* This is the inventory to use for the crafting
|
||||
*/
|
||||
public Inventory inventory;
|
||||
|
||||
/**
|
||||
* This is the list of the slots that the crafting logic should look for the input item stacks.
|
||||
*/
|
||||
public int[] inputSlots;
|
||||
/**
|
||||
* This is the list of the slots that the crafting logic should look for the input item stacks.
|
||||
*/
|
||||
public int[] inputSlots;
|
||||
|
||||
/**
|
||||
* This is the list for the slots that the crafting logic should look fot the output item stacks.
|
||||
*/
|
||||
public int[] outputSlots;
|
||||
/**
|
||||
* This is the list for the slots that the crafting logic should look fot the output item stacks.
|
||||
*/
|
||||
public int[] outputSlots;
|
||||
|
||||
/**
|
||||
* This is the constructor, not a lot to say here :P
|
||||
*
|
||||
* @param recipeName
|
||||
* @param parentTile
|
||||
* @param energy
|
||||
* @param inputs
|
||||
* @param outputs
|
||||
* @param inventory
|
||||
* @param inputSlots
|
||||
* @param outputSlots
|
||||
*/
|
||||
public RecipeCrafter(String recipeName, TileMachineBase parentTile, BasicSink energy, int inputs, int outputs, Inventory inventory, int[] inputSlots, int[] outputSlots) {
|
||||
this.recipeName = recipeName;
|
||||
this.parentTile = parentTile;
|
||||
this.energy = energy;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.inventory = inventory;
|
||||
this.inputSlots = inputSlots;
|
||||
this.outputSlots = outputSlots;
|
||||
}
|
||||
/**
|
||||
* This is the constructor, not a lot to say here :P
|
||||
*
|
||||
* @param recipeName
|
||||
* @param parentTile
|
||||
* @param energy
|
||||
* @param inputs
|
||||
* @param outputs
|
||||
* @param inventory
|
||||
* @param inputSlots
|
||||
* @param outputSlots
|
||||
*/
|
||||
public RecipeCrafter(String recipeName, TileMachineBase parentTile, BasicSink energy, int inputs, int outputs, Inventory inventory, int[] inputSlots, int[] outputSlots) {
|
||||
this.recipeName = recipeName;
|
||||
this.parentTile = parentTile;
|
||||
this.energy = energy;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.inventory = inventory;
|
||||
this.inputSlots = inputSlots;
|
||||
this.outputSlots = outputSlots;
|
||||
}
|
||||
|
||||
|
||||
public IBaseRecipeType currentRecipe;
|
||||
public int currentTickTime = 0;
|
||||
public IBaseRecipeType currentRecipe;
|
||||
public int currentTickTime = 0;
|
||||
double lastEnergy;
|
||||
|
||||
/**
|
||||
* Call this on the tile tick
|
||||
*/
|
||||
public void updateEntity() {
|
||||
if (currentRecipe == null) {//It will now look for new recipes.
|
||||
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
||||
if(recipe.canCraft(parentTile) && hasAllInputs(recipe)){//This checks to see if it has all of the inputs
|
||||
boolean canGiveInvAll = true;
|
||||
for (int i = 0; i < recipe.getOutputs().size(); i++) {//This checks to see if it can fit all of the outputs
|
||||
if (!canFitStack(recipe.getOutputs().get(i), outputSlots[i])) {
|
||||
canGiveInvAll = false;
|
||||
}
|
||||
}
|
||||
if(canGiveInvAll){
|
||||
currentRecipe = recipe;//Sets the current recipe then syncs
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(lastEnergy != energy.getEnergyStored()){
|
||||
/**
|
||||
* Call this on the tile tick
|
||||
*/
|
||||
public void updateEntity() {
|
||||
if (currentRecipe == null) {//It will now look for new recipes.
|
||||
for (IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)) {
|
||||
if (recipe.canCraft(parentTile) && hasAllInputs(recipe)) {//This checks to see if it has all of the inputs
|
||||
boolean canGiveInvAll = true;
|
||||
for (int i = 0; i < recipe.getOutputs().size(); i++) {//This checks to see if it can fit all of the outputs
|
||||
if (!canFitStack(recipe.getOutputs().get(i), outputSlots[i])) {
|
||||
canGiveInvAll = false;
|
||||
}
|
||||
}
|
||||
if (canGiveInvAll) {
|
||||
currentRecipe = recipe;//Sets the current recipe then syncs
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastEnergy != energy.getEnergyStored()) {
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
} else {
|
||||
if(!hasAllInputs()){//If it doesn't have all the inputs reset
|
||||
currentRecipe = null;
|
||||
currentTickTime = 0;
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
if (currentRecipe != null && currentTickTime >= currentRecipe.tickTime()) {//If it has reached the recipe tick time
|
||||
boolean canGiveInvAll = true;
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {//Checks to see if it can fit the output
|
||||
if (!canFitStack(currentRecipe.getOutputs().get(i), outputSlots[i])) {
|
||||
canGiveInvAll = false;
|
||||
}
|
||||
}
|
||||
ArrayList<Integer> filledSlots = new ArrayList<Integer>();//The slots that have been filled
|
||||
if (canGiveInvAll && currentRecipe.onCraft(parentTile)) {
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
|
||||
if (!filledSlots.contains(outputSlots[i])) {//checks it has not been filled
|
||||
fitStack(currentRecipe.getOutputs().get(i), outputSlots[i]);//fills the slot with the output stack
|
||||
filledSlots.add(outputSlots[i]);
|
||||
}
|
||||
}
|
||||
useAllInputs();//this uses all the inputs
|
||||
currentRecipe = null;//resets
|
||||
currentTickTime = 0;
|
||||
//Force sync after craft
|
||||
} else {
|
||||
if (!hasAllInputs()) {//If it doesn't have all the inputs reset
|
||||
currentRecipe = null;
|
||||
currentTickTime = 0;
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
if (currentRecipe != null && currentTickTime >= currentRecipe.tickTime()) {//If it has reached the recipe tick time
|
||||
boolean canGiveInvAll = true;
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {//Checks to see if it can fit the output
|
||||
if (!canFitStack(currentRecipe.getOutputs().get(i), outputSlots[i])) {
|
||||
canGiveInvAll = false;
|
||||
}
|
||||
}
|
||||
ArrayList<Integer> filledSlots = new ArrayList<Integer>();//The slots that have been filled
|
||||
if (canGiveInvAll && currentRecipe.onCraft(parentTile)) {
|
||||
for (int i = 0; i < currentRecipe.getOutputs().size(); i++) {
|
||||
if (!filledSlots.contains(outputSlots[i])) {//checks it has not been filled
|
||||
fitStack(currentRecipe.getOutputs().get(i), outputSlots[i]);//fills the slot with the output stack
|
||||
filledSlots.add(outputSlots[i]);
|
||||
}
|
||||
}
|
||||
useAllInputs();//this uses all the inputs
|
||||
currentRecipe = null;//resets
|
||||
currentTickTime = 0;
|
||||
//Force sync after craft
|
||||
parentTile.syncWithAll();
|
||||
parentTile.needsSync = false;
|
||||
parentTile.ticksSinceLastSync = 0;
|
||||
}
|
||||
} else if (currentRecipe != null && currentTickTime < currentRecipe.tickTime()) {
|
||||
if (energy.canUseEnergy(currentRecipe.euPerTick())) {//This checks to see if it can use the power
|
||||
if(!parentTile.getWorldObj().isRemote){//remove the power on the server side only
|
||||
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
|
||||
}
|
||||
currentTickTime++;//increase the ticktime
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (currentRecipe != null && currentTickTime < currentRecipe.tickTime()) {
|
||||
if (energy.canUseEnergy(currentRecipe.euPerTick())) {//This checks to see if it can use the power
|
||||
if (!parentTile.getWorldObj().isRemote) {//remove the power on the server side only
|
||||
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
|
||||
}
|
||||
currentTickTime++;//increase the ticktime
|
||||
parentTile.needsSync = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastEnergy = energy.getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAllInputs(){
|
||||
if(currentRecipe == null){
|
||||
return false;
|
||||
}
|
||||
for(ItemStack input : currentRecipe.getInputs()){
|
||||
Boolean hasItem = false;
|
||||
for(int inputSlot : inputSlots){//Checks to see if it can find the input
|
||||
if(ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true, true) && inventory.getStackInSlot(inputSlot).stackSize >= input.stackSize){
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if(!hasItem)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean hasAllInputs() {
|
||||
if (currentRecipe == null) {
|
||||
return false;
|
||||
}
|
||||
for (ItemStack input : currentRecipe.getInputs()) {
|
||||
Boolean hasItem = false;
|
||||
for (int inputSlot : inputSlots) {//Checks to see if it can find the input
|
||||
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true, true) && inventory.getStackInSlot(inputSlot).stackSize >= input.stackSize) {
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if (!hasItem)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasAllInputs(IBaseRecipeType recipeType){
|
||||
if(recipeType == null){
|
||||
return false;
|
||||
}
|
||||
for(ItemStack input : recipeType.getInputs()){
|
||||
Boolean hasItem = false;
|
||||
for(int inputslot : inputSlots){
|
||||
if(ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true, true)){
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if(!hasItem)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean hasAllInputs(IBaseRecipeType recipeType) {
|
||||
if (recipeType == null) {
|
||||
return false;
|
||||
}
|
||||
for (ItemStack input : recipeType.getInputs()) {
|
||||
Boolean hasItem = false;
|
||||
for (int inputslot : inputSlots) {
|
||||
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true, true)) {
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if (!hasItem)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void useAllInputs(){
|
||||
if(currentRecipe == null){
|
||||
return;
|
||||
}
|
||||
for(ItemStack input : currentRecipe.getInputs()){
|
||||
for(int inputSlot : inputSlots){//Uses all of the inputs
|
||||
if(ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true, true)){
|
||||
inventory.decrStackSize(inputSlot, input.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void useAllInputs() {
|
||||
if (currentRecipe == null) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack input : currentRecipe.getInputs()) {
|
||||
for (int inputSlot : inputSlots) {//Uses all of the inputs
|
||||
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true, true)) {
|
||||
inventory.decrStackSize(inputSlot, input.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canFitStack(ItemStack stack, int slot) {//Checks to see if it can fit the stack
|
||||
if (stack == null) {
|
||||
return true;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {
|
||||
return true;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) {
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean canFitStack(ItemStack stack, int slot) {//Checks to see if it can fit the stack
|
||||
if (stack == null) {
|
||||
return true;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {
|
||||
return true;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) {
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void fitStack(ItemStack stack, int slot) {//This fits a stack into a slot
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {//If the slot is empty set the contents
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
return;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) {//If the slot has stuff in
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {//Check to see if it fits
|
||||
ItemStack newStack = stack.copy();
|
||||
newStack.stackSize = inventory.getStackInSlot(slot).stackSize + stack.stackSize;//Sets the new stack size
|
||||
inventory.setInventorySlotContents(slot, newStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void fitStack(ItemStack stack, int slot) {//This fits a stack into a slot
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
if (inventory.getStackInSlot(slot) == null) {//If the slot is empty set the contents
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
return;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) {//If the slot has stuff in
|
||||
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {//Check to see if it fits
|
||||
ItemStack newStack = stack.copy();
|
||||
newStack.stackSize = inventory.getStackInSlot(slot).stackSize + stack.stackSize;//Sets the new stack size
|
||||
inventory.setInventorySlotContents(slot, newStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
NBTTagCompound data = tag.getCompoundTag("Crater");
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
NBTTagCompound data = tag.getCompoundTag("Crater");
|
||||
|
||||
currentTickTime = data.getInteger("currentTickTime");
|
||||
}
|
||||
currentTickTime = data.getInteger("currentTickTime");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
data.setDouble("currentTickTime", currentTickTime);
|
||||
data.setDouble("currentTickTime", currentTickTime);
|
||||
|
||||
tag.setTag("Crater", data);
|
||||
}
|
||||
tag.setTag("Crater", data);
|
||||
}
|
||||
|
||||
public boolean isActive(){
|
||||
return currentRecipe != null && currentTickTime != 0;
|
||||
}
|
||||
public boolean isActive() {
|
||||
return currentRecipe != null && currentTickTime != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
package techreborn.api.recipe;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RecipeHanderer {
|
||||
|
||||
/**
|
||||
* This is the array list of all of the recipes for all of the machines
|
||||
*/
|
||||
public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>();
|
||||
/**
|
||||
* This is the array list of all of the recipes for all of the machines
|
||||
*/
|
||||
public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>();
|
||||
|
||||
/**
|
||||
* This is a backedup clone of the master recipeList
|
||||
*/
|
||||
public static ArrayList<IBaseRecipeType> recipeListBackup = new ArrayList<IBaseRecipeType>();
|
||||
/**
|
||||
* This is a backedup clone of the master recipeList
|
||||
*/
|
||||
public static ArrayList<IBaseRecipeType> recipeListBackup = new ArrayList<IBaseRecipeType>();
|
||||
|
||||
/**
|
||||
* Use this to get all of the recipes form a recipe name
|
||||
* @param name the name that the recipe was resisted as.
|
||||
* @return A list of all the recipes of a given name.
|
||||
*/
|
||||
public static List<IBaseRecipeType> getRecipeClassFromName(String name){
|
||||
List<IBaseRecipeType> baseRecipeList = new ArrayList<IBaseRecipeType>();
|
||||
for(IBaseRecipeType baseRecipe : recipeList){
|
||||
if(baseRecipe.getRecipeName().equals(name)){
|
||||
baseRecipeList.add(baseRecipe);
|
||||
}
|
||||
}
|
||||
return baseRecipeList;
|
||||
}
|
||||
/**
|
||||
* Use this to get all of the recipes form a recipe name
|
||||
*
|
||||
* @param name the name that the recipe was resisted as.
|
||||
* @return A list of all the recipes of a given name.
|
||||
*/
|
||||
public static List<IBaseRecipeType> getRecipeClassFromName(String name) {
|
||||
List<IBaseRecipeType> baseRecipeList = new ArrayList<IBaseRecipeType>();
|
||||
for (IBaseRecipeType baseRecipe : recipeList) {
|
||||
if (baseRecipe.getRecipeName().equals(name)) {
|
||||
baseRecipeList.add(baseRecipe);
|
||||
}
|
||||
}
|
||||
return baseRecipeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a recipe to the system
|
||||
* @param recipe The recipe to add to the system.
|
||||
*/
|
||||
public static void addRecipe(IBaseRecipeType recipe){
|
||||
if(recipe == null){
|
||||
return;
|
||||
}
|
||||
if(recipeList.contains(recipe)){
|
||||
return;
|
||||
}
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
/**
|
||||
* Add a recipe to the system
|
||||
*
|
||||
* @param recipe The recipe to add to the system.
|
||||
*/
|
||||
public static void addRecipe(IBaseRecipeType recipe) {
|
||||
if (recipe == null) {
|
||||
return;
|
||||
}
|
||||
if (recipeList.contains(recipe)) {
|
||||
return;
|
||||
}
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,14 +5,13 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class AlloySmelterRecipe extends BaseRecipe {
|
||||
|
||||
public AlloySmelterRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick)
|
||||
{
|
||||
super("alloySmelterRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
public AlloySmelterRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
|
||||
super("alloySmelterRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class AssemblingMachineRecipe extends BaseRecipe {
|
||||
|
||||
public AssemblingMachineRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick)
|
||||
{
|
||||
super("assemblingMachineRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
public AssemblingMachineRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
|
||||
super("assemblingMachineRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,20 +5,19 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class CentrifugeRecipe extends BaseRecipe {
|
||||
|
||||
public CentrifugeRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick)
|
||||
{
|
||||
super("centrifugeRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
if(output2 != null)
|
||||
outputs.add(output2);
|
||||
if(output3 != null)
|
||||
outputs.add(output3);
|
||||
if(output4 != null)
|
||||
outputs.add(output4);
|
||||
}
|
||||
public CentrifugeRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick) {
|
||||
super("centrifugeRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
if (output2 != null)
|
||||
outputs.add(output2);
|
||||
if (output3 != null)
|
||||
outputs.add(output3);
|
||||
if (output4 != null)
|
||||
outputs.add(output4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class ChemicalReactorRecipe extends BaseRecipe {
|
||||
|
||||
public ChemicalReactorRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick)
|
||||
{
|
||||
super("chemicalReactorRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
public ChemicalReactorRecipe(ItemStack input1, ItemStack input2, ItemStack output1, int tickTime, int euPerTick) {
|
||||
super("chemicalReactorRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,58 +9,63 @@ import techreborn.tiles.TileGrinder;
|
|||
|
||||
public class GrinderRecipe extends BaseRecipe {
|
||||
|
||||
public FluidStack fluidStack;
|
||||
public FluidStack fluidStack;
|
||||
|
||||
public GrinderRecipe(ItemStack input1, FluidStack fluidStack, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick)
|
||||
{
|
||||
super("grinderRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
if(output2 != null)
|
||||
outputs.add(output2);
|
||||
if(output3 != null)
|
||||
outputs.add(output3);
|
||||
if(output4 != null)
|
||||
outputs.add(output4);
|
||||
this.fluidStack = fluidStack;
|
||||
}
|
||||
public GrinderRecipe(ItemStack input1, FluidStack fluidStack, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime, int euPerTick) {
|
||||
super("grinderRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
if (output2 != null)
|
||||
outputs.add(output2);
|
||||
if (output3 != null)
|
||||
outputs.add(output3);
|
||||
if (output4 != null)
|
||||
outputs.add(output4);
|
||||
this.fluidStack = fluidStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraft(TileEntity tile) {
|
||||
if(tile instanceof TileGrinder){
|
||||
TileGrinder grinder = (TileGrinder) tile;
|
||||
if(grinder.tank.getFluid() == null){
|
||||
return false;
|
||||
}
|
||||
if(grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()){
|
||||
if(grinder.tank.getFluidAmount() >= fluidStack.amount){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canCraft(TileEntity tile) {
|
||||
if (fluidStack == null) {
|
||||
return true;
|
||||
}
|
||||
if (tile instanceof TileGrinder) {
|
||||
TileGrinder grinder = (TileGrinder) tile;
|
||||
if (grinder.tank.getFluid() == null) {
|
||||
return false;
|
||||
}
|
||||
if (grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
|
||||
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCraft(TileEntity tile) {
|
||||
if(tile instanceof TileGrinder) {
|
||||
TileGrinder grinder = (TileGrinder) tile;
|
||||
if(grinder.tank.getFluid() == null){
|
||||
return false;
|
||||
}
|
||||
if(grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()){
|
||||
if(grinder.tank.getFluidAmount() >= fluidStack.amount){
|
||||
if(grinder.tank.getFluidAmount() > 0){
|
||||
grinder.tank.setFluid(new FluidStack(fluidStack.getFluid(), grinder.tank.getFluidAmount() - fluidStack.amount));
|
||||
} else {
|
||||
grinder.tank.setFluid(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onCraft(TileEntity tile) {
|
||||
if (fluidStack == null) {
|
||||
return true;
|
||||
}
|
||||
if (tile instanceof TileGrinder) {
|
||||
TileGrinder grinder = (TileGrinder) tile;
|
||||
if (grinder.tank.getFluid() == null) {
|
||||
return false;
|
||||
}
|
||||
if (grinder.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
|
||||
if (grinder.tank.getFluidAmount() >= fluidStack.amount) {
|
||||
if (grinder.tank.getFluidAmount() > 0) {
|
||||
grinder.tank.setFluid(new FluidStack(fluidStack.getFluid(), grinder.tank.getFluidAmount() - fluidStack.amount));
|
||||
} else {
|
||||
grinder.tank.setFluid(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,15 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class ImplosionCompressorRecipe extends BaseRecipe {
|
||||
|
||||
public ImplosionCompressorRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, int tickTime, int euPerTick) {
|
||||
super("implosionCompressorRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
if(output2 != null)
|
||||
outputs.add(output2);
|
||||
}
|
||||
public ImplosionCompressorRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, int tickTime, int euPerTick) {
|
||||
super("implosionCompressorRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
if (output2 != null)
|
||||
outputs.add(output2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,18 +5,17 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class IndustrialSawmillRecipe extends BaseRecipe {
|
||||
|
||||
public IndustrialSawmillRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, int tickTime, int euPerTick)
|
||||
{
|
||||
super("industrialSawmillRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(input2 != null)
|
||||
inputs.add(input2);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
if(output2 != null)
|
||||
outputs.add(output2);
|
||||
if(output3 != null)
|
||||
outputs.add(output3);
|
||||
}
|
||||
public IndustrialSawmillRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, int tickTime, int euPerTick) {
|
||||
super("industrialSawmillRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (input2 != null)
|
||||
inputs.add(input2);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
if (output2 != null)
|
||||
outputs.add(output2);
|
||||
if (output3 != null)
|
||||
outputs.add(output3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,11 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class LatheRecipe extends BaseRecipe {
|
||||
|
||||
public LatheRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick)
|
||||
{
|
||||
super("latheRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
public LatheRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
|
||||
super("latheRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,11 @@ import techreborn.api.recipe.BaseRecipe;
|
|||
|
||||
public class PlateCuttingMachineRecipe extends BaseRecipe {
|
||||
|
||||
public PlateCuttingMachineRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick)
|
||||
{
|
||||
super("plateCuttingMachineRecipe", tickTime, euPerTick);
|
||||
if(input1 != null)
|
||||
inputs.add(input1);
|
||||
if(output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
public PlateCuttingMachineRecipe(ItemStack input1, ItemStack output1, int tickTime, int euPerTick) {
|
||||
super("plateCuttingMachineRecipe", tickTime, euPerTick);
|
||||
if (input1 != null)
|
||||
inputs.add(input1);
|
||||
if (output1 != null)
|
||||
outputs.add(output1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
|
||||
package techreborn.api.recipe.machines;
|
||||
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI") package techreborn.api.recipe.machines;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
|
||||
package techreborn.api.recipe;
|
||||
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI") package techreborn.api.recipe;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue