aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/miscutil/core/util')
-rw-r--r--src/Java/miscutil/core/util/ItemUtils.java156
-rw-r--r--src/Java/miscutil/core/util/Utils.java60
2 files changed, 197 insertions, 19 deletions
diff --git a/src/Java/miscutil/core/util/ItemUtils.java b/src/Java/miscutil/core/util/ItemUtils.java
new file mode 100644
index 0000000000..e2c07aa104
--- /dev/null
+++ b/src/Java/miscutil/core/util/ItemUtils.java
@@ -0,0 +1,156 @@
+package miscutil.core.util;
+
+import java.util.ArrayList;
+
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.oredict.ShapedOreRecipe;
+import cpw.mods.fml.common.registry.GameRegistry;
+
+public class ItemUtils {
+
+ public static ItemStack getItemStackOfItem(Boolean modToCheck, String mod_itemname_meta){
+ if (modToCheck){
+ try{
+ Item em = null;
+
+ Item em1 = Utils.getItem(mod_itemname_meta);
+ Utils.LOG_WARNING("Found: "+em1.toString());
+ if (!em1.equals(null)){
+ em = em1;
+ }
+ else {
+ em = null;
+ return null;
+ }
+ if (!em.equals(null)){
+ ItemStack returnStack = new ItemStack(em,1,16);
+ return returnStack;
+ }
+ Utils.LOG_WARNING(mod_itemname_meta+" not found.");
+ return null;
+ } catch (NullPointerException e) {
+ Utils.LOG_ERROR(mod_itemname_meta+" not found. [NULL]");
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static void recipeBuilder(Object slot_1, Object slot_2, Object slot_3, Object slot_4, Object slot_5, Object slot_6, Object slot_7, Object slot_8, Object slot_9, ItemStack resultItem){
+
+ ArrayList<Object> validSlots = new ArrayList<Object>();
+
+ //, String lineFirst, String lineSecond, String lineThird
+ Utils.LOG_INFO("Trying to add a recipe for "+resultItem.toString());
+ String a,b,c,d,e,f,g,h,i;
+ //ItemStack empty = new ItemStack(Blocks.air);
+ if (slot_1 == null){ a = " ";} else { a = "1";validSlots.add('1');validSlots.add(slot_1);}
+ Utils.LOG_WARNING(a);
+ if (slot_2 == null){ b = " ";} else { b = "2";validSlots.add('2');validSlots.add(slot_2);}
+ Utils.LOG_WARNING(b);
+ if (slot_3 == null){ c = " ";} else { c = "3";validSlots.add('3');validSlots.add(slot_3);}
+ Utils.LOG_WARNING(c);
+ if (slot_4 == null){ d = " ";} else { d = "4";validSlots.add('4');validSlots.add(slot_4);}
+ Utils.LOG_WARNING(d);
+ if (slot_5 == null){ e = " ";} else { e = "5";validSlots.add('5');validSlots.add(slot_5);}
+ Utils.LOG_WARNING(e);
+ if (slot_6 == null){ f = " ";} else { f = "6";validSlots.add('6');validSlots.add(slot_6);}
+ Utils.LOG_WARNING(f);
+ if (slot_7 == null){ g = " ";} else { g = "7";validSlots.add('7');validSlots.add(slot_7);}
+ Utils.LOG_WARNING(g);
+ if (slot_8 == null){ h = " ";} else { h = "8";validSlots.add('8');validSlots.add(slot_8);}
+ Utils.LOG_WARNING(h);
+ if (slot_9 == null){ i = " ";} else { i = "9";validSlots.add('9');validSlots.add(slot_9);}
+ Utils.LOG_WARNING(i);
+
+
+ Utils.LOG_ERROR("_______");
+ String lineOne = a+b+c;
+ Utils.LOG_ERROR("|"+a+"|"+b+"|"+c+"|");
+ Utils.LOG_ERROR("_______");
+ String lineTwo = d+e+f;
+ Utils.LOG_ERROR("|"+d+"|"+e+"|"+f+"|");
+ Utils.LOG_ERROR("_______");
+ String lineThree = g+h+i;
+ Utils.LOG_ERROR("|"+g+"|"+h+"|"+i+"|");
+ Utils.LOG_ERROR("_______");
+
+ validSlots.add(0, lineOne);
+ validSlots.add(1, lineTwo);
+ validSlots.add(2, lineThree);
+ Boolean AadvancedLog = true;
+ if (AadvancedLog){
+ int j = 0;
+ int l = validSlots.size();
+ Utils.LOG_WARNING("l:"+l);
+ while (j <= l) {
+ Utils.LOG_WARNING("j:"+j);
+ if (j <= 2){
+ Utils.LOG_WARNING("ArrayList Values: "+validSlots.get(j));
+ Utils.LOG_WARNING("Adding 1.");
+ j++;
+ }
+ else if (j >= 3){
+ Utils.LOG_WARNING("ArrayList Values: '"+validSlots.get(j)+"' "+validSlots.get(j+1));
+ if (j < (l-2)){
+ Utils.LOG_WARNING("Adding 2.");
+ j=j+2;
+ }
+ else {
+ Utils.LOG_WARNING("Done iteration.");
+ break;
+ }
+ }
+ else if (j == l){
+ Utils.LOG_WARNING("Done iteration.");
+ break;
+ }
+ if (validSlots.get(j) instanceof String || validSlots.get(j) instanceof ItemStack){
+ //Utils.LOG_WARNING("Is Valid: "+validSlots.get(j));
+ }
+ }
+ }
+
+ try {
+ Utils.LOG_WARNING("validSlots to array: "+validSlots.toArray());
+ Object[] validSlotsArray = (Object[]) validSlots.toArray();
+
+ for(int j = 0; j < validSlotsArray.length; j++)
+ {
+ Utils.LOG_ERROR(""+validSlotsArray[j]);
+ }
+ try {
+ try {
+ try {
+ GameRegistry.addRecipe(new ShapedOreRecipe(resultItem.copy(), (Object[]) validSlots.toArray()));
+ Utils.LOG_INFO("Success! Added a recipe for "+resultItem.toString());
+ }
+ catch (ClassCastException r){
+ Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName());
+ r.printStackTrace();
+ System.exit(1);
+ }
+ }
+ catch (NullPointerException o){
+
+ Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName());
+ o.printStackTrace();
+ System.exit(1);
+ }
+ }
+ catch (ClassCastException r){
+ Utils.LOG_WARNING("@@@: Casting to ObjectArray Failed :(");
+ }
+ }
+ catch(NullPointerException k){
+ k.getMessage();
+ k.getClass();
+ k.printStackTrace();
+ k.getLocalizedMessage();
+ Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName());
+ System.exit(1);
+ }
+ }
+
+}
diff --git a/src/Java/miscutil/core/util/Utils.java b/src/Java/miscutil/core/util/Utils.java
index 10375f3f8e..a4b75d87d7 100644
--- a/src/Java/miscutil/core/util/Utils.java
+++ b/src/Java/miscutil/core/util/Utils.java
@@ -2,6 +2,7 @@ package miscutil.core.util;
import static gregtech.api.enums.GT_Values.F;
+import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
@@ -138,6 +139,12 @@ public class Utils {
return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]);
}
+ public static ItemStack getItemStack(String fqrn, int Size) // fqrn = fully qualified resource name
+ {
+ String[] fqrnSplit = fqrn.split(":");
+ return GameRegistry.findItemStack(fqrnSplit[0], fqrnSplit[1], Size);
+ }
+
public static Item getItemInPlayersHand(){
Minecraft mc = Minecraft.getMinecraft();
Item heldItem = null;
@@ -146,28 +153,21 @@ public class Utils {
}catch(NullPointerException e){return null;}
if (heldItem != null){
- return heldItem;
- }
+ return heldItem;
+ }
return null;
- }
-
- public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){
- GameRegistry.addRecipe(
- new ItemStack(resultBlock),
- slot_1, slot_2, slot_3,
- slot_4, slot_5, slot_6,
- slot_7, slot_8, slot_9);
}
-
- public static void recipeBuilderItem(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Item resultItem){
- GameRegistry.addRecipe(
- new ItemStack(resultItem),
- slot_1, slot_2, slot_3,
- slot_4, slot_5, slot_6,
- slot_7, slot_8, slot_9);
- }
-
+
+ /*public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){
+ GameRegistry.addRecipe(new ItemStack(resultBlock),
+ new Object[] {"ABC", "DEF", "GHI",
+ 'A',slot_1,'B',slot_2,'C',slot_3,
+ 'D',slot_4,'E',slot_5,'F',slot_6,
+ 'G',slot_7,'H',slot_8,'I',slot_9
+ });
+ }*/
+
public static String checkCorrectMiningToolForBlock(Block currentBlock, World currentWorld){
String correctTool = "";
if (!currentWorld.isRemote){
@@ -182,4 +182,26 @@ public class Utils {
return correctTool;
}
+
+ /**
+ *
+ * @param colorStr e.g. "#FFFFFF"
+ * @return String - formatted "rgb(0,0,0)"
+ */
+ public static String hex2Rgb(String hexString) {
+ Color c = new Color(
+ Integer.valueOf(hexString.substring(1, 3), 16),
+ Integer.valueOf(hexString.substring(3, 5), 16),
+ Integer.valueOf(hexString.substring(5, 7), 16));
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("rgb(");
+ sb.append(c.getRed());
+ sb.append(",");
+ sb.append(c.getGreen());
+ sb.append(",");
+ sb.append(c.getBlue());
+ sb.append(")");
+ return sb.toString();
+ }
}