mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-20 12:19:48 +00:00
69 lines
2.3 KiB
Java
69 lines
2.3 KiB
Java
package tconstruct.library.crafting;
|
|
|
|
import java.util.ArrayList;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.item.*;
|
|
|
|
public class DryingRackRecipes {
|
|
public static ArrayList<DryingRecipe> recipes = new ArrayList<>();
|
|
|
|
public static void addDryingRecipe(Object input, int time, Object output) {
|
|
ItemStack inputItem;
|
|
ItemStack outputItem;
|
|
|
|
if (input instanceof ItemStack) inputItem = (ItemStack) input;
|
|
else if (input instanceof Item) inputItem = new ItemStack((Item) input, 1, 0);
|
|
else if (input instanceof Block) inputItem = new ItemStack((Block) input, 1, 0);
|
|
else throw new RuntimeException("Drying recipe input is invalid!");
|
|
|
|
if (output instanceof ItemStack) outputItem = (ItemStack) output;
|
|
else if (output instanceof Item) outputItem = new ItemStack((Item) output, 1, 0);
|
|
else if (output instanceof Block) outputItem = new ItemStack((Block) output, 1, 0);
|
|
else throw new RuntimeException("Drying recipe output is invalid!");
|
|
|
|
recipes.add(new DryingRecipe(inputItem, time, outputItem));
|
|
}
|
|
|
|
public static int getDryingTime(ItemStack input) {
|
|
for (DryingRecipe r : recipes) {
|
|
if (r.matches(input)) return r.time;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public static ItemStack getDryingResult(ItemStack input) {
|
|
for (DryingRecipe r : recipes) {
|
|
if (r.matches(input)) return r.getResult();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static class DryingRecipe {
|
|
public final int time;
|
|
public final ItemStack input;
|
|
public final ItemStack result;
|
|
|
|
DryingRecipe(ItemStack input, int time, ItemStack result) {
|
|
this.time = time;
|
|
this.input = input;
|
|
this.result = result;
|
|
}
|
|
|
|
public boolean matches(ItemStack input) {
|
|
// makes all drying rack recipies compatible with stuff killed by a frying pan
|
|
if (input.hasTagCompound()) {
|
|
input = input.copy();
|
|
input.getTagCompound().removeTag("frypanKill");
|
|
if (input.getTagCompound().hasNoTags()) input.setTagCompound(null);
|
|
}
|
|
return ItemStack.areItemStacksEqual(this.input, input);
|
|
}
|
|
|
|
public ItemStack getResult() {
|
|
return result.copy();
|
|
}
|
|
}
|
|
}
|