Got the RollingMachine working

This commit is contained in:
Modmuss50 2015-04-15 17:27:05 +01:00
parent 8e7d6b011e
commit b7ccae4b8c
7 changed files with 278 additions and 151 deletions

View file

@ -0,0 +1,112 @@
package techreborn.api;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RollingMachineRecipe {
private final List<IRecipe> recipes = new ArrayList<IRecipe>();
public static final RollingMachineRecipe instance = new RollingMachineRecipe();
public void addRecipe(ItemStack output, Object... components) {
String s = "";
int i = 0;
int j = 0;
int k = 0;
if(components[i] instanceof String[]) {
String as[] = (String[])components[i++];
for(int l = 0; l < as.length; l++) {
String s2 = as[l];
k++;
j = s2.length();
s = (new StringBuilder()).append(s).append(s2).toString();
}
} else {
while(components[i] instanceof String) {
String s1 = (String)components[i++];
k++;
j = s1.length();
s = (new StringBuilder()).append(s).append(s1).toString();
}
}
HashMap hashmap = new HashMap();
for(; i < components.length; i += 2) {
Character character = (Character)components[i];
ItemStack itemstack1 = null;
if(components[i + 1] instanceof Item) {
itemstack1 = new ItemStack((Item)components[i + 1]);
} else if(components[i + 1] instanceof Block) {
itemstack1 = new ItemStack((Block)components[i + 1], 1, -1);
} else if(components[i + 1] instanceof ItemStack) {
itemstack1 = (ItemStack)components[i + 1];
}
hashmap.put(character, itemstack1);
}
ItemStack recipeArray[] = new ItemStack[j * k];
for(int i1 = 0; i1 < j * k; i1++) {
char c = s.charAt(i1);
if(hashmap.containsKey(Character.valueOf(c))) {
recipeArray[i1] = ((ItemStack)hashmap.get(Character.valueOf(c))).copy();
} else {
recipeArray[i1] = null;
}
}
recipes.add(new ShapedRecipes(j, k, recipeArray, output));
}
public void addShapelessRecipe(ItemStack output, Object... components) {
List<ItemStack> ingredients = new ArrayList<ItemStack>();
for(int j = 0; j < components.length; j++) {
Object obj = components[j];
if(obj instanceof ItemStack) {
ingredients.add(((ItemStack)obj).copy());
continue;
}
if(obj instanceof Item) {
ingredients.add(new ItemStack((Item)obj));
continue;
}
if(obj instanceof Block) {
ingredients.add(new ItemStack((Block)obj));
} else {
throw new RuntimeException("Invalid shapeless recipe!");
}
}
recipes.add(new ShapelessRecipes(output, ingredients));
}
public ItemStack findMatchingRecipe(InventoryCrafting inv, World world) {
for(int k = 0; k < recipes.size(); k++) {
IRecipe irecipe = (IRecipe)recipes.get(k);
if(irecipe.matches(inv, world)) {
return irecipe.getCraftingResult(inv);
}
}
return null;
}
public List<IRecipe> getRecipeList() {
return recipes;
}
}

View file

@ -1,119 +0,0 @@
package techreborn.api;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class RollingMachineRecipie {
ItemStack inputItem1, inputItem2, inputItem3, inputItem4, inputItem5, inputItem6,
inputItem7, inputItem8, inputItem9;
ItemStack output1;
int tickTime;
public RollingMachineRecipie(ItemStack inputItem1, ItemStack inputItem2, ItemStack inputItem3, ItemStack inputItem4,
ItemStack inputItem5, ItemStack inputItem6, ItemStack inputItem7, ItemStack inputItem8, ItemStack inputItem9,
ItemStack output1, int tickTime) {
this.inputItem1 = inputItem1;
this.inputItem2 = inputItem2;
this.inputItem3 = inputItem3;
this.inputItem4 = inputItem4;
this.inputItem5 = inputItem5;
this.inputItem6 = inputItem6;
this.inputItem7 = inputItem7;
this.inputItem8 = inputItem8;
this.inputItem9 = inputItem9;
this.output1 = output1;
this.tickTime = tickTime;
}
public RollingMachineRecipie(Item inputItem1, Item inputItem2, Item inputItem3, Item inputItem4, Item inputItem5,
Item inputItem6, Item inputItem7, Item inputItem8, Item inputItem9, int inputAmount,
Item output1, int tickTime) {
if (inputItem1 != null)
this.inputItem1 = new ItemStack(inputItem1, inputAmount);
if (inputItem2 != null)
this.inputItem2 = new ItemStack(inputItem2, inputAmount);
if (inputItem3 != null)
this.inputItem3 = new ItemStack(inputItem3, inputAmount);
if (inputItem4 != null)
this.inputItem4 = new ItemStack(inputItem4, inputAmount);
if (inputItem5 != null)
this.inputItem5 = new ItemStack(inputItem5, inputAmount);
if (inputItem6 != null)
this.inputItem6 = new ItemStack(inputItem6, inputAmount);
if (inputItem7 != null)
this.inputItem7 = new ItemStack(inputItem7, inputAmount);
if (inputItem8 != null)
this.inputItem8 = new ItemStack(inputItem8, inputAmount);
if (inputItem9 != null)
this.inputItem9 = new ItemStack(inputItem9, inputAmount);
this.output1 = new ItemStack(output1);
this.tickTime = tickTime;
;
}
public RollingMachineRecipie(RollingMachineRecipie rollingmachineRecipie) {
this.inputItem1 = rollingmachineRecipie.getInputItem1();
this.inputItem2 = rollingmachineRecipie.getInputItem2();
this.inputItem3 = rollingmachineRecipie.getInputItem3();
this.inputItem4 = rollingmachineRecipie.getInputItem4();
this.inputItem5 = rollingmachineRecipie.getInputItem5();
this.inputItem6 = rollingmachineRecipie.getInputItem6();
this.inputItem7 = rollingmachineRecipie.getInputItem7();
this.inputItem8 = rollingmachineRecipie.getInputItem8();
this.inputItem9 = rollingmachineRecipie.getInputItem9();
this.output1 = rollingmachineRecipie.getOutput1();
this.tickTime = rollingmachineRecipie.getTickTime();
}
public ItemStack getInputItem1() {
return inputItem1;
}
public ItemStack getInputItem2() {
return inputItem2;
}
public ItemStack getInputItem3() {
return inputItem3;
}
public ItemStack getInputItem4() {
return inputItem4;
}
public ItemStack getInputItem5() {
return inputItem5;
}
public ItemStack getInputItem6() {
return inputItem6;
}
public ItemStack getInputItem7() {
return inputItem7;
}
public ItemStack getInputItem8() {
return inputItem8;
}
public ItemStack getInputItem9() {
return inputItem9;
}
public ItemStack getOutput1() {
return output1;
}
public int getTickTime() {
return tickTime;
}
}

View file

@ -1,5 +1,6 @@
package techreborn.api;
import net.minecraft.item.ItemStack;
import techreborn.util.ItemUtils;
import java.util.ArrayList;
@ -7,7 +8,7 @@ import java.util.ArrayList;
public final class TechRebornAPI {
public static ArrayList<CentrifugeRecipie> centrifugeRecipies = new ArrayList<CentrifugeRecipie>();
public static ArrayList<RollingMachineRecipie> rollingmachineRecipes = new ArrayList<RollingMachineRecipie>();
public static ArrayList<RollingMachineRecipe> rollingmachineRecipes = new ArrayList<RollingMachineRecipe>();
public static void registerCentrifugeRecipe(CentrifugeRecipie recipie) {
@ -26,21 +27,14 @@ public final class TechRebornAPI {
centrifugeRecipies.add(recipie);
}
public static void registerRollingMachineRecipe(RollingMachineRecipie recipie) {
boolean shouldAdd = true;
for (CentrifugeRecipie centrifugeRecipie : centrifugeRecipies) {
if (ItemUtils.isItemEqual(centrifugeRecipie.getInputItem(), recipie.getInputItem1(), false, true)) {
try {
throw new RegisteredItemRecipe("Item " + recipie.getInputItem1().getUnlocalizedName() + " is already being used in a recipe for the RollingMachine");
} catch (RegisteredItemRecipe registeredItemRecipe) {
registeredItemRecipe.printStackTrace();
shouldAdd = false;
}
}
}
if (shouldAdd)
rollingmachineRecipes.add(recipie);
public static void addRollingMachinceRecipe(ItemStack output, Object... components) {
RollingMachineRecipe.instance.addRecipe(output, components);
}
public void addShapelessRollingMachinceRecipe(ItemStack output, Object... components) {
RollingMachineRecipe.instance.addShapelessRecipe(output, components);
}
}