aboutsummaryrefslogtreecommitdiff
path: root/src/Java
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-07-05 21:05:53 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-07-05 21:05:53 +1000
commita2dd2d3da3876b3711b0067a4055eacc1780275a (patch)
tree722742fd8ed81ce7b67d7304f7feb138c522de0d /src/Java
parent3302e20803b5259ae2a8d4cc9e297240f8caf167 (diff)
downloadGT5-Unofficial-a2dd2d3da3876b3711b0067a4055eacc1780275a.tar.gz
GT5-Unofficial-a2dd2d3da3876b3711b0067a4055eacc1780275a.tar.bz2
GT5-Unofficial-a2dd2d3da3876b3711b0067a4055eacc1780275a.zip
$ More work trying to fix recipe generation.
Diffstat (limited to 'src/Java')
-rw-r--r--src/Java/gtPlusPlus/api/objects/Logger.java4
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java162
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java164
3 files changed, 106 insertions, 224 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/Logger.java b/src/Java/gtPlusPlus/api/objects/Logger.java
index 1ecdaa9e86..672cb52304 100644
--- a/src/Java/gtPlusPlus/api/objects/Logger.java
+++ b/src/Java/gtPlusPlus/api/objects/Logger.java
@@ -139,6 +139,10 @@ public class Logger {
if (CORE.DEVENV || CORE.DEBUG)
modLogger.info("[WorldGen] "+s);
}
+
+ public static void RECIPE(String string) {
+ modLogger.info("[Recipe] "+string);
+ }
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java b/src/Java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java
index a81bd8f340..de10c11845 100644
--- a/src/Java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java
@@ -1,5 +1,6 @@
package gtPlusPlus.api.objects.minecraft;
+import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.data.Pair;
import net.minecraft.item.ItemStack;
@@ -8,7 +9,7 @@ import net.minecraftforge.oredict.ShapedOreRecipe;
public class ShapedRecipe {
private final static String CHARS = "abcdefghijklmnop";
- public final ShapedOreRecipe mRecipe;
+ public ShapedOreRecipe mRecipe;
public ShapedRecipe(
Object aInput1, Object aInput2, Object aInput3,
@@ -21,79 +22,114 @@ public class ShapedRecipe {
}
public ShapedRecipe(Object[] aInputs, ItemStack aOutput) {
- char shape[] = new char[9];
String aGridWhole = "";
String aGrid[] = new String[3];
- //Build a Pair for each slot
- AutoMap<Pair<Character, Object>> aRecipePairs = new AutoMap<Pair<Character, Object>>();
- int aCharSlot = 0;
- for (Object stack : aInputs) {
- if (stack != null) {
- aRecipePairs.put(new Pair<Character, Object>(CHARS.charAt(aCharSlot++), stack));
- }
- else {
- aRecipePairs.put(new Pair<Character, Object>(' ', (ItemStack) null));
- }
- }
+ //Just to be safe
+ try {
+
+ //Check if the output is invalid
+ if (aOutput != null) {
+ Object[] mVarags2 = null;
+ Logger.RECIPE("Generating Shaped Crafting Recipe for "+aOutput.getDisplayName());
- //If we have enough valid slots, iterate them and build a String which represents the entire grid.
- //If this String is the correct length, we will split it into thirds and build the grid String array.
- if (aRecipePairs.size() == 9) {
- for (Pair<Character, Object> h : aRecipePairs) {
- if (h.getKey() != null) {
- aGridWhole += String.valueOf(h.getKey());
+ //Build a Pair for each slot
+ AutoMap<Pair<Character, Object>> aRecipePairs = new AutoMap<Pair<Character, Object>>();
+ int aCharSlot = 0;
+ for (Object stack : aInputs) {
+ if (stack != null) {
+ aRecipePairs.put(new Pair<Character, Object>(CHARS.charAt(aCharSlot++), stack));
+ }
+ else {
+ aRecipePairs.put(new Pair<Character, Object>(' ', (ItemStack) null));
+ }
}
+
+ //If we have enough valid slots, iterate them and build a String which represents the entire grid.
+ //If this String is the correct length, we will split it into thirds and build the grid String array.
+ if (aRecipePairs.size() == 9) {
+
+ Logger.RECIPE("9 Char|Object pairs registered for recipe.");
+
+ for (Pair<Character, Object> h : aRecipePairs) {
+ if (h.getKey() != null) {
+ aGridWhole += String.valueOf(h.getKey());
+ Logger.RECIPE("Adding '"+String.valueOf(h.getKey())+"' to aGridWhole.");
+ }
+ }
+
+ Logger.RECIPE("aGridWhole: "+aGridWhole+" | size: "+aGridWhole.length());
+
+ //Build crafting grid
+ if (aGridWhole.length() == 9) {
+ Logger.RECIPE("aGridWhole size == 9");
+ aGrid[0] = ""+aGridWhole.charAt(0)+aGridWhole.charAt(1)+aGridWhole.charAt(2);
+ aGrid[1] = ""+aGridWhole.charAt(3)+aGridWhole.charAt(4)+aGridWhole.charAt(5);
+ aGrid[2] = ""+aGridWhole.charAt(6)+aGridWhole.charAt(7)+aGridWhole.charAt(8);
+ }
+
+ //Rebuild the Map without spaces
+ aRecipePairs.clear();
+ aCharSlot = 0;
+ int counter = 3;
+ for (Object stack : aInputs) {
+ if (stack != null) {
+ aRecipePairs.put(new Pair<Character, Object>(CHARS.charAt(aCharSlot), stack));
+ Logger.RECIPE("Registering Pair of '"+CHARS.charAt(aCharSlot)+" and a "+stack.getClass().getSimpleName()+" object.");
+ aCharSlot++;
+ counter++;
+ }
+ }
+
+ Logger.RECIPE("Counter started at 3, counter is now at "+counter+". Trying to create Varag array with a size of "+((counter-3)*2));
+
+ //Register the shaped grid straight to the varags
+ mVarags2 = new Object[((counter-3)*2)];
+ mVarags2[0] = aGrid[0];
+ mVarags2[1] = aGrid[1];
+ mVarags2[2] = aGrid[2];
+
+ //Add Each Char, then Item to the varags, sequentially.
+ int counter2 = 3;
+ for (Pair<Character, Object> r : aRecipePairs) {
+ char c = r.getKey();
+ Object o = r.getValue();
+ mVarags2[counter2] = (char) c;
+ mVarags2[counter2+1] = o;
+ counter2 += 2;
+ }
+ }
+
+ //Try set the recipe for this object.
+ ShapedOreRecipe testRecipe = null;
+ try {
+ testRecipe = new ShapedOreRecipe(aOutput, mVarags2);
+ }
+ catch (Throwable t) {
+ Logger.RECIPE("Error thrown when making a ShapedOreRecipe object.");
+ t.printStackTrace();
+ }
+ if (testRecipe == null) {
+ this.mRecipe = null;
+ Logger.RECIPE("Failed to generate a shaped recipe.");
+ }
+ else {
+ this.mRecipe = testRecipe;
+ Logger.RECIPE("Generated a shaped recipe successfully.");
+ }
}
- if (aGridWhole.length() == 9) {
- aGrid[0] = ""+aGridWhole.charAt(0)+aGridWhole.charAt(1)+aGridWhole.charAt(2);
- aGrid[1] = ""+aGridWhole.charAt(3)+aGridWhole.charAt(4)+aGridWhole.charAt(5);
- aGrid[2] = ""+aGridWhole.charAt(6)+aGridWhole.charAt(7)+aGridWhole.charAt(8);
- }
- }
- //Rebuild the Map without spaces
- aRecipePairs.clear();
- aCharSlot = 0;
- int counter = 3;
- for (Object stack : aInputs) {
- if (stack != null) {
- aRecipePairs.put(new Pair<Character, Object>(CHARS.charAt(aCharSlot++), stack));
- counter++;
+ //Output was not valid
+ else {
+ this.mRecipe = null;
+ Logger.RECIPE("Failed to generate a shaped recipe. Output was not valid.");
}
- }
- //Register the shaped grid straight to the varags
- Object[] mVarags2 = new Object[counter];
- mVarags2[0] = aGrid[0];
- mVarags2[1] = aGrid[1];
- mVarags2[2] = aGrid[2];
-
- //Add Each Char, then Item to the varags, sequentially.
- int counter2 = 3;
- for (Pair<Character, Object> r : aRecipePairs) {
- char c = r.getKey();
- Object o = r.getValue();
- mVarags2[counter2] = (char) c;
- mVarags2[counter2+1] = o;
- counter2 += 2;
- }
-
- //Try set the recipe for this object.
- ShapedOreRecipe testRecipe = null;
- try {
- testRecipe = new ShapedOreRecipe(aOutput, mVarags2);
- }
- catch (Throwable t) {
-
- }
- if (testRecipe == null) {
- this.mRecipe = null;
+
}
- else {
- this.mRecipe = testRecipe;
+ catch(Throwable t) {
+ this.mRecipe = null;
}
-
}
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
index 2ec7598f4c..8b2ab43cf2 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
@@ -33,7 +33,7 @@ public class RecipeUtils {
final ArrayList<Object> validSlots = new ArrayList<>();
if (resultItem == null){
- Logger.WARNING("Found a recipe with an invalid output, yet had a valid inputs. Using Dummy output so recipe can be found..");
+ Logger.WARNING("[Recipe] Found a recipe with an invalid output, yet had a valid inputs. Using Dummy output so recipe can be found..");
resultItem = ItemUtils.getItemStackOfAmountFromOreDict("givemeabrokenitem", 1);
RegistrationHandler.recipesFailed++;
//return false;
@@ -42,8 +42,8 @@ public class RecipeUtils {
if ((slot_1 == null) && (slot_2 == null) && (slot_3 == null) &&
(slot_4 == null) && (slot_5 == null) && (slot_6 == null) &&
(slot_7 == null) && (slot_8 == null) && (slot_9 == null)){
- Logger.INFO("Found a recipe with 0 inputs, yet had a valid output.");
- Logger.INFO("Error found while adding a recipe for: "+resultItem.getDisplayName()+" | Please report this issue on Github.");
+ Logger.INFO("[Recipe] Found a recipe with 0 inputs, yet had a valid output.");
+ Logger.INFO("[Recipe] Error found while adding a recipe for: "+resultItem.getDisplayName()+" | Please report this issue on Github.");
RegistrationHandler.recipesFailed++;
return false;
}
@@ -546,165 +546,7 @@ public class RecipeUtils {
public final boolean isValid;
public InternalRecipeObject(Object[] aInputs, ItemStack aOutput, boolean gtRecipe) {
-
mOutput = aOutput != null ? aOutput.copy() : null;
- /*String line1 = "", line2 = "", line3 = "";
- String h = "abcdefghi";
- char blank = ' ';
- int counter = 0;
- char s[] = new char[9];
- ItemStack[] vInputs = new ItemStack[9];
- Object[] tInputs = aInputs.clone();
-
- if (tInputs.length >= 8 && aOutput != null) {
-
- for (Object o : tInputs) {
- if (o instanceof String || o instanceof ItemStack) {
- s[counter] = h.charAt(counter);
- }
- else if (o == null) {
- s[counter] = blank;
- }
- counter++;
- }
-
- for (int y=0;y<9;y++){
- if (tInputs.length > y) {
- if (tInputs[y] instanceof String) {
- vInputs[y] = ItemUtils.getItemStackOfAmountFromOreDict((String) tInputs[y], 1);
- }
- else if (tInputs[y] instanceof ItemStack) {
- vInputs[y] = (ItemStack) tInputs[y];
- }
- else {
- vInputs[y] = null;
- Logger.INFO("[Recipe] Invalid Item in shapped recipe outputting "+mOutput != null ? mOutput.getDisplayName() : "BAD OUTPUT ITEM" + " | Type: "+tInputs[y] != null ? tInputs[y].getClass().getName() : "Unable to determine class of invalid object.");
- }
- }
- else {
- vInputs[y] = null;
- }
- }
- }
-
- for (int i=0;i<3;i++) {
- line1 = line1 + s[i];
- }
- for (int i=3;i<6;i++) {
- line2 = line2 + s[i];
- }
- for (int i=6;i<9;i++) {
- line3 = line3 + s[i];
- }
-
- //line1 = StringUtils.join(s, null, 0, 2);
- //line2 = StringUtils.join(s, null, 3, 5);
- //line3 = StringUtils.join(s, null, 6, 8);
-
-
- Object[] mVarags = new Object[18];
- int mSlotCount = 0;
-
- ItemStack[] a32 = new ItemStack[9];
- char[] a16 = new char[9];
-
- for (mSlotCount=0;mSlotCount<9;mSlotCount++) {
- if (mSlotCount >= vInputs.length-1) {
- mVarags[mSlotCount] = String.valueOf(blank);
- a16[mSlotCount] = blank;
- mVarags[mSlotCount+1] = (ItemStack) null;
- a32[mSlotCount] = (ItemStack) null;
- }
- else {
- if (s[mSlotCount] != ' ') {
- mVarags[mSlotCount] = String.valueOf(s[mSlotCount]);
- a16[mSlotCount] = Character.valueOf(s[mSlotCount]);
- }
- else {
- mVarags[mSlotCount] = String.valueOf(blank);
- a16[mSlotCount] = blank;
- }
- if (vInputs[mSlotCount] != null) {
- mVarags[mSlotCount+1] = vInputs[mSlotCount].copy();
- a32[mSlotCount] = vInputs[mSlotCount].copy();
- }
- else {
- mVarags[mSlotCount+1] = (ItemStack) null;
- a32[mSlotCount] = (ItemStack) null;
- }
- }
-
- }
-
- int nullCount = 0;
-
- for (Object m : mVarags){
- if (m == null) {
- nullCount++;
- }
- }
- Object[] mVarags2 = new Object[mVarags.length-nullCount+3];
- mVarags2[0]=line1;
- mVarags2[1]=line2;
- mVarags2[2]=line3;
- for (int i=3;i<(mVarags.length-nullCount+3);i++) {
- if (mVarags[i] instanceof String) {
- mVarags2[i] = (char) ((String) mVarags[i]).charAt(0);
- }
- else if (mVarags[i] instanceof ItemStack) {
- mVarags2[i] = (ItemStack) mVarags[i];
- }
- }
-
- int jhr = 0;
- for (Object u : mVarags2) {
- if (u != null) {
- if (u instanceof ItemStack) {
- ItemStack g = (ItemStack) u;
- Logger.INFO("mVarags2: "+(g).getDisplayName());
- }
- else if (u instanceof String) {
- Logger.INFO("mVarags2: "+(String) u);
- }
- else if (u instanceof Character || u instanceof String) {
- char n;
- if (u instanceof String) {
- n = ((String) u).charAt(0);
- }
- else if (u instanceof Character){
- n = (char) u;
- }
- else {
- n = ' ';
- }
- Logger.INFO("mVarags2: "+n);
- }
- else {
- Logger.INFO("mVarags2: Invalid Type. Type: "+u.getClass().getName());
- }
- }
- jhr++;
- }
-
- ShapedOreRecipe d = null;
- try {
- d = new ShapedOreRecipe(
- aOutput,
- mVarags2);
- }
- catch (Throwable t) {
-
- }*/
-
-
- /*if (mOutput == null || d == null || (line1 == null || line2 == null || line3 == null) || !ItemUtils.checkForInvalidItems(d.getRecipeOutput())) {
- isValid = false;
- }
- else {
- isValid = true;
- }*/
-
-
ShapedRecipe r = new ShapedRecipe(aInputs, aOutput);
if (r != null && r.mRecipe != null) {
isValid = true;