Find sawmill recipes from all other recipes.
This commit is contained in:
parent
21dd44def6
commit
f2cbd23994
1 changed files with 72 additions and 16 deletions
|
@ -24,40 +24,96 @@
|
|||
|
||||
package techreborn.init.recipes;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import reborncore.api.recipe.RecipeHandler;
|
||||
import reborncore.common.util.OreUtil;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.api.recipe.machines.IndustrialSawmillRecipe;
|
||||
import techreborn.items.ItemDusts;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class IndustrialSawmillRecipes extends RecipeMethods {
|
||||
static FluidStack WATER = new FluidStack(FluidRegistry.WATER, 1000);
|
||||
|
||||
public static void init() {
|
||||
register(getStack(Blocks.LOG, 1, true), getMaterial("water", Type.CELL), WATER, 100, 128, getStack(Blocks.PLANKS, 8, true), ItemDusts.getDustByName("sawDust", 3), getStack(Items.PAPER,1));
|
||||
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container() {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventoryCrafting.setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> logs = OreDictionary.getOres("logWood");
|
||||
for (ItemStack logStack : logs) {
|
||||
if (logStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ItemStack newStack = logStack.copy();
|
||||
newStack.setItemDamage(i);
|
||||
inventoryCrafting.setInventorySlotContents(0, newStack);
|
||||
ItemStack output = findMatchingRecipe(inventoryCrafting);
|
||||
if (!output.isEmpty()) {
|
||||
if (ItemUtils.isInputEqual("plankWood", output, false, false, false)) {
|
||||
addRecipe(newStack.copy(), output.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inventoryCrafting.setInventorySlotContents(0, logStack.copy());
|
||||
ItemStack output = findMatchingRecipe(inventoryCrafting);
|
||||
if (!output.isEmpty()) {
|
||||
if (ItemUtils.isInputEqual("plankWood", output, false, false, false)) {
|
||||
addRecipe(logStack.copy(), output.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack findMatchingRecipe(InventoryCrafting inv) {
|
||||
IRecipe recipe;
|
||||
for (int i = 0; i < CraftingManager.getInstance().getRecipeList().size(); i++) {
|
||||
recipe = CraftingManager.getInstance().getRecipeList().get(i);
|
||||
if (recipe.matches(inv, null)) {
|
||||
return recipe.getCraftingResult(inv);
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
}
|
||||
|
||||
public static void addRecipe(ItemStack log, ItemStack plank) {
|
||||
register(log, getMaterial("water", Type.CELL), WATER, 100, 128, plank, ItemDusts.getDustByName("sawDust", 3), getStack(Items.PAPER, 1));
|
||||
register(log, new ItemStack(Items.WATER_BUCKET), WATER, 100, 128, plank, ItemDusts.getDustByName("sawDust", 3), getStack(Items.PAPER, 1));
|
||||
}
|
||||
|
||||
static void register(ItemStack input1, ItemStack input2, FluidStack fluid, int ticks, int euPerTick, ItemStack... outputs) {
|
||||
if (outputs.length == 3) {
|
||||
RecipeHandler.addRecipe(new IndustrialSawmillRecipe(input1, input2,
|
||||
fluid, outputs[0], outputs[1], outputs[2], ticks, euPerTick));
|
||||
}
|
||||
else if (outputs.length == 2) {
|
||||
fluid, outputs[0], outputs[1], outputs[2], ticks, euPerTick, false));
|
||||
} else if (outputs.length == 2) {
|
||||
RecipeHandler.addRecipe(new IndustrialSawmillRecipe(input1, input2,
|
||||
fluid, outputs[0], outputs[1], null, ticks, euPerTick));
|
||||
}
|
||||
else if (outputs.length == 1) {
|
||||
fluid, outputs[0], outputs[1], null, ticks, euPerTick, false));
|
||||
} else if (outputs.length == 1) {
|
||||
RecipeHandler.addRecipe(new IndustrialSawmillRecipe(input1, input2,
|
||||
fluid, outputs[0], null, null, ticks, euPerTick));
|
||||
}
|
||||
else {
|
||||
fluid, outputs[0], null, null, ticks, euPerTick, false));
|
||||
} else {
|
||||
throw new InvalidParameterException("Invalid industrial sawmill outputs: " + outputs);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue