aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/minecraft
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2021-05-20 23:07:24 +0000
committerAlkalus <draknyte1@hotmail.com>2021-05-20 23:07:24 +0000
commit7881c840421c191e8c4249fc303e184fa1cbf9a8 (patch)
tree0e1f8d8d19ca14e14dfb16c1ed49750935612dfa /src/Java/gtPlusPlus/core/util/minecraft
parentde40c882cb16535deae1c29b22f1a535747db536 (diff)
parent5316a0ffcbc403e17a06d4c9e28d57e202f0aafe (diff)
downloadGT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.gz
GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.bz2
GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.zip
Merged in MultiFixes (pull request #11)
MultiFixes
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/minecraft')
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java145
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java26
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java23
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java102
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java17
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java198
6 files changed, 474 insertions, 37 deletions
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java
index f0b93a32dc..287820404a 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java
@@ -3,6 +3,7 @@ package gtPlusPlus.core.util.minecraft;
import static gregtech.api.GregTech_API.*;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.HashMap;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -101,7 +102,147 @@ public class HazmatUtils {
addProtection(aItem);
}
Logger.INFO("[Hazmat] Registered EMT Items as hazmat gear.");
- }
+ }
+
+ if (LoadedMods.isModLoaded("DraconicEvolution")) {
+ AutoMap<Field> aItemFields = new AutoMap<Field>();
+ Class aItemsDE = ReflectionUtils.getClass("com.brandon3055.draconicevolution.ModItems");
+
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicHelm"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicChest"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicLeggs"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "draconicBoots"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernHelm"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernChest"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernLeggs"));
+ aItemFields.add(ReflectionUtils.getField(aItemsDE, "wyvernBoots"));
+ AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>();
+ for (Field aItemField : aItemFields) {
+ Item aItemObject = null;
+ if (aItemField != null) {
+ try {
+ aItemObject = (Item) aItemField.get(null);
+ }
+ catch (Exception t) {
+ t.printStackTrace();
+ }
+ }
+ if (aItemObject != null) {
+ aItemMap.add(ItemUtils.getSimpleStack(aItemObject));
+ }
+ else {
+ Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsDE.getName());
+ }
+ }
+ Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Draconic Evolution Items as hazmat gear.");
+ for (ItemStack aItem : aItemMap) {
+ addProtection(aItem);
+ }
+ Logger.INFO("[Hazmat] Registered Draconic Evolution Items as hazmat gear.");
+ }
+
+ if (LoadedMods.isModLoaded("TaintedMagic")) {
+ AutoMap<Field> aItemFields = new AutoMap<Field>();
+ Class aItemsTaintedMagic = ReflectionUtils.getClass("taintedmagic.common.registry.ItemRegistry");
+
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressHelmet"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressChestplate"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemShadowFortressLeggings"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemVoidwalkerBoots"));
+ AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>();
+ for (Field aItemField : aItemFields) {
+ Item aItemObject = null;
+ if (aItemField != null) {
+ try {
+ aItemObject = (Item) aItemField.get(null);
+ }
+ catch (Exception t) {
+ t.printStackTrace();
+ }
+ }
+ if (aItemObject != null) {
+ aItemMap.add(ItemUtils.getSimpleStack(aItemObject));
+ }
+ else {
+ Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsTaintedMagic.getName());
+ }
+ }
+ Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Tainted Magic Items as hazmat gear.");
+ for (ItemStack aItem : aItemMap) {
+ addProtection(aItem);
+ }
+ Logger.INFO("[Hazmat] Registered Tainted Magic Items as hazmat gear.");
+ }
+
+ if (LoadedMods.isModLoaded("WitchingGadgets")) {
+ AutoMap<Field> aItemFields = new AutoMap<Field>();
+ Class aItemsTaintedMagic = ReflectionUtils.getClass("witchinggadgets.common.WGContent");
+
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialHelm"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialChest"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialLegs"));
+ aItemFields.add(ReflectionUtils.getField(aItemsTaintedMagic, "ItemPrimordialBoots"));
+ AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>();
+ for (Field aItemField : aItemFields) {
+ Item aItemObject = null;
+ if (aItemField != null) {
+ try {
+ aItemObject = (Item) aItemField.get(null);
+ }
+ catch (Exception t) {
+ t.printStackTrace();
+ }
+ }
+ if (aItemObject != null) {
+ aItemMap.add(ItemUtils.getSimpleStack(aItemObject));
+ }
+ else {
+ Logger.INFO("[Hazmat] Could not get "+aItemField.getName()+" from "+aItemsTaintedMagic.getName());
+ }
+ }
+ Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Witching Gadgets Items as hazmat gear.");
+ for (ItemStack aItem : aItemMap) {
+ addProtection(aItem);
+ }
+ Logger.INFO("[Hazmat] Registered Witching Gadgets Items as hazmat gear.");
+ }
+
+ if (LoadedMods.isModLoaded("ThaumicTinkerer")) {
+ /*
+ AutoMap<Item> aItems = new AutoMap<Item>();
+ Class aMainTT = ReflectionUtils.getClass("thaumic.tinkerer.common.ThaumicTinkerer");
+ Class aItemRegistryTT = ReflectionUtils.getClass("thaumic.tinkerer.common.registry.TTRegistry");
+ Field aRegistryInstance = ReflectionUtils.getField(aMainTT, "registry");
+ Object aRegistry = ReflectionUtils.getFieldValue(aRegistryInstance);
+ Method aFuckingStupidMethodHandlingMethod = ReflectionUtils.getMethod(aItemRegistryTT, "getFirstItemFromClass", new Class[] {Class.class});
+ Item aIchorHelm = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemHelm")});
+ Item aIchorChest = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemChest")});
+ Item aIchorLegs = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemLegs")});
+ Item aIchorBoots = (Item) ReflectionUtils.invokeNonBool(aRegistry, aFuckingStupidMethodHandlingMethod, new Object[] {ReflectionUtils.getClass("thaumic.tinkerer.common.item.kami.armor.ItemGemBoots")});
+ aItems.add(aIchorHelm);
+ aItems.add(aIchorChest);
+ aItems.add(aIchorLegs);
+ aItems.add(aIchorBoots);
+ AutoMap<ItemStack> aItemMap = new AutoMap<ItemStack>();
+ int aIndex = 0;
+ for (Item aItem : aItems) {
+ Item aItemObject = null;
+ if (aItem != null) {
+ aItemMap.add(ItemUtils.getSimpleStack(aItemObject));
+ }
+ else {
+ Logger.INFO("[Hazmat] Could not get item "+aIndex+" from "+aItemRegistryTT.getName());
+ }
+ aIndex++;
+ }
+ Logger.INFO("[Hazmat] Registering "+aItemMap.size()+" Thaumic Tinkerer Items as hazmat gear.");
+ for (ItemStack aItem : aItemMap) {
+ addProtection(aItem);
+ }
+ Logger.INFO("[Hazmat] Registered Thaumic Tinkerer Items as hazmat gear.");
+ */
+ Logger.INFO("[Hazmat] Did not register Thaumic Tinkerer Items as hazmat gear.");
+ }
if (LoadedMods.isModLoaded("GraviSuite")) {
AutoMap<Field> aItemFields = new AutoMap<Field>();
@@ -288,7 +429,7 @@ public class HazmatUtils {
Logger.INFO("==========================================================");
return false;
}
- Logger.INFO("[Hazmat] Registering " + aVanStack.getDisplayName() + " for full Hazmat protection.");
+ Logger.INFO("[Hazmat] Registering " + ItemUtils.getItemName(aVanStack) + " for full Hazmat protection.");
GT_ItemStack aStack = getGtStackFromVanilla(aVanStack);
AutoMap<Boolean> aAdded = new AutoMap<Boolean>();
aAdded.put(addProtection_Frost(aStack));
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java
index aaa81a0057..fe67c88d69 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java
@@ -2,6 +2,11 @@ package gtPlusPlus.core.util.minecraft;
import java.util.Random;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.util.GT_Utility;
+import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy_RTG;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
@@ -58,5 +63,26 @@ public class InventoryUtils {
}
}
+
+ public static void sortInventoryItems(MetaTileEntity aTile) {
+ sortInventoryItems(aTile.getBaseMetaTileEntity());
+ }
+
+ public static void sortInventoryItems(IGregTechTileEntity aBaseMetaTileEntity) {
+ IInventory mInv = aBaseMetaTileEntity.getIInventory(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getZCoord());
+ AutoMap<ItemStack> aInvContents = new AutoMap<ItemStack>();
+ int aSize = mInv.getSizeInventory();
+ for (int slot=0; slot<aSize; slot++) {
+ aInvContents.put(mInv.getStackInSlot(slot));
+ }
+ ItemStack[] mInventory = aInvContents.toArray();
+ for (int i = 0; i < mInventory.length; i++) {
+ for (int j = i + 1; j < mInventory.length; j++) {
+ if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) {
+ GT_Utility.moveStackFromSlotAToSlotB(aBaseMetaTileEntity, aBaseMetaTileEntity, j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1);
+ }
+ }
+ }
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
index 70b635583d..09e7f51e06 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
@@ -451,9 +451,10 @@ public class ItemUtils {
final ItemStack smallDust = ItemUtils.getSimpleStack(output[1]);
final ItemStack tinyDust = ItemUtils.getSimpleStack(output[2]);
-
+ CORE.RA.addpackagerRecipe(ItemList.Schematic_Dust.get(1), smallDust, tinyDust, normalDust);
+
if (ItemUtils.checkForInvalidItems(tinyDust) && ItemUtils.checkForInvalidItems(normalDust)) {
- if (RecipeUtils.recipeBuilder(
+ if (RecipeUtils.addShapedRecipe(
tinyDust, tinyDust, tinyDust,
tinyDust, tinyDust, tinyDust,
tinyDust, tinyDust, tinyDust,
@@ -464,7 +465,7 @@ public class ItemUtils {
Logger.WARNING("9 Tiny dust to 1 Dust Recipe: "+materialName+" - Failed");
}
- if (RecipeUtils.recipeBuilder(
+ if (RecipeUtils.addShapedRecipe(
normalDust, null, null,
null, null, null,
null, null, null,
@@ -477,7 +478,7 @@ public class ItemUtils {
}
if (ItemUtils.checkForInvalidItems(smallDust) && ItemUtils.checkForInvalidItems(normalDust)) {
- if (RecipeUtils.recipeBuilder(
+ if (RecipeUtils.addShapedRecipe(
smallDust, smallDust, null,
smallDust, smallDust, null,
null, null, null,
@@ -487,7 +488,7 @@ public class ItemUtils {
else {
Logger.WARNING("4 Small dust to 1 Dust Recipe: "+materialName+" - Failed");
}
- if (RecipeUtils.recipeBuilder(
+ if (RecipeUtils.addShapedRecipe(
null, normalDust, null,
null, null, null,
null, null, null,
@@ -1136,8 +1137,8 @@ public class ItemUtils {
String aDisplay = null;
try {
aDisplay = (aStack.getUnlocalizedName()).trim();
-
- } catch (Throwable t) {
+ }
+ catch (Throwable t) {
aDisplay = aStack.getItem().getUnlocalizedName();
}
if (aDisplay == null || aDisplay.length() <= 0) {
@@ -1368,4 +1369,12 @@ public class ItemUtils {
return aOther;
}
+ public static boolean areItemsEqual(ItemStack aStack1, ItemStack aStack2) {
+ return areItemsEqual(aStack1, aStack2, true);
+ }
+
+ public static boolean areItemsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) {
+ return GT_Utility.areStacksEqual(aStack1, aStack2, aIgnoreNBT);
+ }
+
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java
index b0623d429d..7ed4d887cc 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java
@@ -2,6 +2,7 @@ package gtPlusPlus.core.util.minecraft;
import static gtPlusPlus.core.item.ModItems.ZZZ_Empty;
+import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.Entity;
@@ -413,6 +414,107 @@ public class NBTUtils {
return false;
}
+ public static Map getTagMap(NBTTagCompound aNBT) {
+ Map tagMap = new HashMap();
+ if (!aNBT.hasNoTags()) {
+ Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap");
+ if (mInternalMap != null && !mInternalMap.isEmpty()) {
+ tagMap.putAll(mInternalMap);
+ }
+ }
+ return tagMap;
+ }
+
+ public static boolean isTagString(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (aValue instanceof String) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isTagInteger(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (int.class.isInstance(aValue) || aValue instanceof Integer) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isTagLong(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (long.class.isInstance(aValue) || aValue instanceof Long) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isTagFloat(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (float.class.isInstance(aValue) || aValue instanceof Float) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isTagDouble(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (double.class.isInstance(aValue) || aValue instanceof Double) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isTagBoolean(NBTTagCompound aNBT, String aTagName) {
+ Map<?, ?> aTagMap = getTagMap(aNBT);
+ if (aTagMap != null && !aTagMap.isEmpty()) {
+ for (Map.Entry<?, ?> e : aTagMap.entrySet()) {
+ if (e.getKey().equals(aTagName)) {
+ Object aValue = e.getValue();
+ if (boolean.class.isInstance(aValue) || aValue instanceof Boolean) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
public static boolean tryCloneTagCompoundDataIntoSubTag(ItemStack aStack, NBTTagCompound aTagCompound) {
try {
NBTTagCompound aNBT = aTagCompound;
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
index 110b2baf25..24ffa295b7 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java
@@ -4,8 +4,8 @@ import java.util.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
-import gtPlusPlus.core.handler.events.BlockEventHandler;
import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -16,11 +16,20 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
-import thaumcraft.common.lib.FakeThaumcraftPlayer;
public class PlayerUtils {
public static final Map<String, EntityPlayer> mCachedFakePlayers = new WeakHashMap<String, EntityPlayer>();
+ private static final Class mThaumcraftFakePlayer;
+
+ static {
+ if (ReflectionUtils.doesClassExist("thaumcraft.common.lib.FakeThaumcraftPlayer")) {
+ mThaumcraftFakePlayer = ReflectionUtils.getClass("thaumcraft.common.lib.FakeThaumcraftPlayer");
+ }
+ else {
+ mThaumcraftFakePlayer = null;
+ }
+ }
public static void messagePlayer(final EntityPlayer P, final String S){
gregtech.api.util.GT_Utility.sendChatToPlayer(P, S);
@@ -203,7 +212,7 @@ public class PlayerUtils {
public static void cacheFakePlayer(EntityPlayer aPlayer) {
ChunkCoordinates aChunkLocation = aPlayer.getPlayerCoordinates();
// Cache Fake Player
- if (aPlayer instanceof FakePlayer || aPlayer instanceof FakeThaumcraftPlayer
+ if (aPlayer instanceof FakePlayer || (mThaumcraftFakePlayer != null && mThaumcraftFakePlayer.isInstance(aPlayer))
|| (aPlayer.getCommandSenderName() == null
|| aPlayer.getCommandSenderName().length() <= 0)
|| (aPlayer.isEntityInvulnerable() && !aPlayer.canCommandSenderUseCommand(0, "")
@@ -225,7 +234,7 @@ public class PlayerUtils {
cacheFakePlayer(p);
return false;
}
- if (p instanceof FakeThaumcraftPlayer) {
+ if (mThaumcraftFakePlayer != null && mThaumcraftFakePlayer.isInstance(p) ) {
cacheFakePlayer(p);
return false;
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
index 56772f0dc7..a20678c354 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java
@@ -6,11 +6,8 @@ import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.Materials;
-import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
-import gregtech.api.util.GT_ModHandler;
-import gregtech.api.util.GT_OreDictUnificator;
-import gregtech.api.util.GT_Recipe;
-import gregtech.api.util.GT_Utility;
+import gregtech.api.objects.ItemData;
+import gregtech.api.util.*;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gtPlusPlus.GTplusplus;
import gtPlusPlus.api.interfaces.RunnableWithInfo;
@@ -20,9 +17,11 @@ import gtPlusPlus.api.objects.minecraft.ShapedRecipe;
import gtPlusPlus.core.handler.COMPAT_HANDLER;
import gtPlusPlus.core.handler.Recipes.LateRegistrationHandler;
import gtPlusPlus.core.handler.Recipes.RegistrationHandler;
-import gtPlusPlus.core.item.ModItems;
+import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.recipe.common.CI;
+import gtPlusPlus.core.util.data.ArrayUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
@@ -38,15 +37,15 @@ public static int mInvalidID = 1;
//Old Debug Code, useful for finding recipes loading too early.
/*if (gtPlusPlus.GTplusplus.CURRENT_LOAD_PHASE != GTplusplus.INIT_PHASE.POST_INIT) {
- Logger.INFO(ReflectionUtils.getMethodName(1));
- Logger.INFO(ReflectionUtils.getMethodName(2));
- Logger.INFO(ReflectionUtils.getMethodName(3));
- Logger.INFO(ReflectionUtils.getMethodName(4));
- Logger.INFO(ReflectionUtils.getMethodName(5));
- Logger.INFO(ReflectionUtils.getMethodName(6));
- Logger.INFO(ReflectionUtils.getMethodName(7));
- Logger.INFO(ReflectionUtils.getMethodName(8));
- Logger.INFO(ReflectionUtils.getMethodName(9));
+ Logger.RECIPE(ReflectionUtils.getMethodName(1));
+ Logger.RECIPE(ReflectionUtils.getMethodName(2));
+ Logger.RECIPE(ReflectionUtils.getMethodName(3));
+ Logger.RECIPE(ReflectionUtils.getMethodName(4));
+ Logger.RECIPE(ReflectionUtils.getMethodName(5));
+ Logger.RECIPE(ReflectionUtils.getMethodName(6));
+ Logger.RECIPE(ReflectionUtils.getMethodName(7));
+ Logger.RECIPE(ReflectionUtils.getMethodName(8));
+ Logger.RECIPE(ReflectionUtils.getMethodName(9));
System.exit(1);
}*/
@@ -348,15 +347,15 @@ public static int mInvalidID = 1;
if (gtPlusPlus.GTplusplus.CURRENT_LOAD_PHASE != GTplusplus.INIT_PHASE.POST_INIT) {
- Logger.INFO(ReflectionUtils.getMethodName(1));
- Logger.INFO(ReflectionUtils.getMethodName(2));
- Logger.INFO(ReflectionUtils.getMethodName(3));
- Logger.INFO(ReflectionUtils.getMethodName(4));
- Logger.INFO(ReflectionUtils.getMethodName(5));
- Logger.INFO(ReflectionUtils.getMethodName(6));
- Logger.INFO(ReflectionUtils.getMethodName(7));
- Logger.INFO(ReflectionUtils.getMethodName(8));
- Logger.INFO(ReflectionUtils.getMethodName(9));
+ Logger.RECIPE(ReflectionUtils.getMethodName(1));
+ Logger.RECIPE(ReflectionUtils.getMethodName(2));
+ Logger.RECIPE(ReflectionUtils.getMethodName(3));
+ Logger.RECIPE(ReflectionUtils.getMethodName(4));
+ Logger.RECIPE(ReflectionUtils.getMethodName(5));
+ Logger.RECIPE(ReflectionUtils.getMethodName(6));
+ Logger.RECIPE(ReflectionUtils.getMethodName(7));
+ Logger.RECIPE(ReflectionUtils.getMethodName(8));
+ Logger.RECIPE(ReflectionUtils.getMethodName(9));
System.exit(1);
}
@@ -517,6 +516,9 @@ public static int mInvalidID = 1;
else if (o instanceof Item) {
aFiltered[aValid++] = ItemUtils.getSimpleStack((Item) o);
}
+ else if (o instanceof Block) {
+ aFiltered[aValid++] = ItemUtils.getSimpleStack((Block) o);
+ }
else if (o instanceof String) {
aFiltered[aValid++] = o;
}
@@ -536,6 +538,9 @@ public static int mInvalidID = 1;
else if (p instanceof Item) {
validCounter++;
}
+ else if (p instanceof Block) {
+ validCounter++;
+ }
else if (p instanceof String) {
validCounter++;
}
@@ -643,6 +648,151 @@ public static int mInvalidID = 1;
}
+ public static boolean addShapedRecipe(
+ Object Input_1, Object Input_2, Object Input_3,
+ Object Input_4, Object Input_5, Object Input_6,
+ Object Input_7, Object Input_8, Object Input_9,
+ ItemStack aOutputStack) {
+ return addShapedRecipe(new Object[] {Input_1, Input_2, Input_3, Input_4, Input_5, Input_6, Input_7, Input_8, Input_9}, aOutputStack);
+ }
+
+ private static boolean addShapedRecipe(Object[] Inputs, ItemStack aOutputStack) {
+ Object[] Slots = new Object[9];
+
+ String aFullString = "";
+ String aFullStringExpanded = "abcdefghi";
+
+ for (int i=0; i<9; i++) {
+ Object o = Inputs[i];
+
+ if (o instanceof ItemStack) {
+ Slots[i] = ItemUtils.getSimpleStack((ItemStack) o, 1);
+ aFullString += aFullStringExpanded.charAt(i);
+ }
+ else if (o instanceof Item) {
+ Slots[i] = ItemUtils.getSimpleStack((Item) o, 1);
+ aFullString += aFullStringExpanded.charAt(i);
+ }
+ else if (o instanceof Block) {
+ Slots[i] = ItemUtils.getSimpleStack((Block) o, 1);
+ aFullString += aFullStringExpanded.charAt(i);
+ }
+ else if (o instanceof String) {
+ Slots[i] = o;
+ aFullString += aFullStringExpanded.charAt(i);
+ }
+ else if (o instanceof ItemData) {
+ ItemData aData = (ItemData) o;
+ ItemStack aStackFromGT = ItemUtils.getOrePrefixStack(aData.mPrefix, aData.mMaterial.mMaterial, 1);
+ Slots[i] = aStackFromGT;
+ aFullString += aFullStringExpanded.charAt(i);
+ }
+ else if (o == null) {
+ Slots[i] = null;
+ aFullString += " ";
+ }
+ else {
+ Slots[i] = null;
+ Logger.INFO("Cleaned a "+o.getClass().getSimpleName()+" from recipe input.");
+ Logger.INFO("ERROR");
+ CORE.crash("Bad Shaped Recipe.");
+ }
+ }
+ Logger.INFO("Using String: "+aFullString);
+
+ String aRow1 = aFullString.substring(0, 3);
+ String aRow2 = aFullString.substring(3, 6);
+ String aRow3 = aFullString.substring(6, 9);
+ Logger.INFO(""+aRow1);
+ Logger.INFO(""+aRow2);
+ Logger.INFO(""+aRow3);
+
+ String[] aStringData = new String[] {aRow1, aRow2, aRow3};
+ Object[] aDataObject = new Object[19];
+ aDataObject[0] = aStringData;
+ int aIndex = 0;
+
+
+ for (int u=1;u<20;u+=2) {
+ if (aIndex == 9) {
+ break;
+ }
+ if (aFullString.charAt(aIndex) != (' ')) {
+ aDataObject[u] = aFullString.charAt(aIndex);
+ aDataObject[u+1] = Slots[aIndex];
+ Logger.INFO("("+aIndex+") "+aFullString.charAt(aIndex)+" | "+ (Slots[aIndex] instanceof ItemStack ? ItemUtils.getItemName((ItemStack) Slots[aIndex]) : Slots[aIndex] instanceof String ? (String) Slots[aIndex] : "Unknown"));
+ }
+ aIndex++;
+ }
+
+ Logger.INFO("Data Size: "+aDataObject.length);
+ aDataObject = ArrayUtils.removeNulls(aDataObject);
+ Logger.INFO("Clean Size: "+aDataObject.length);
+ Logger.INFO("ArrayData: "+aDataObject.toString());
+
+ ShapedOreRecipe aRecipe = new ShapedOreRecipe(aOutputStack, aDataObject);
+
+ /*ShapedOreRecipe aRecipe = new ShapedOreRecipe(aOutputStack,
+ aStringData,
+ 'a', Slots[0],
+ 'b', Slots[1],
+ 'c', Slots[2],
+ 'd', Slots[3],
+ 'e', Slots[4],
+ 'f', Slots[5],
+ 'g', Slots[6],
+ 'h', Slots[7],
+ 'i', Slots[8]);*/
+
+ int size = COMPAT_HANDLER.mRecipesToGenerate.size();
+ COMPAT_HANDLER.mRecipesToGenerate.put(new InternalRecipeObject2(aRecipe));
+ if (COMPAT_HANDLER.mRecipesToGenerate.size() > size) {
+ if (!COMPAT_HANDLER.areInitItemsLoaded){
+ RegistrationHandler.recipesSuccess++;
+ }
+ else {
+ LateRegistrationHandler.recipesSuccess++;
+ }
+ return true;
+ }
+ return false;
+ }
+ public static class InternalRecipeObject2 implements RunnableWithInfo<String> {
+
+ final ItemStack mOutput;
+ final ShapedOreRecipe mRecipe;
+ final boolean isValid;
+
+ public InternalRecipeObject2(ShapedOreRecipe aRecipe) {
+ mRecipe = aRecipe;
+ mOutput = aRecipe.getRecipeOutput();
+ if (mOutput != null) {
+ this.isValid = true;
+ }
+ else {
+ this.isValid = false;
+ }
+ }
+
+ @Override
+ public void run() {
+ if (this.isValid) {
+ GameRegistry.addRecipe(mRecipe);
+ }
+ else {
+ Logger.INFO("[Fix] Invalid shapped recipe outputting "+mOutput != null ? mOutput.getDisplayName() : "Bad Output Item");
+ }
+ }
+
+ @Override
+ public String getInfoData() {
+ if (mOutput != null && mOutput instanceof ItemStack) {
+ return ((ItemStack) mOutput).getDisplayName();
+ }
+ return "";
+ }
+
+ }
}