aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r--src/Java/gtPlusPlus/core/util/Utils.java5
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java95
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java152
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java75
4 files changed, 171 insertions, 156 deletions
diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java
index e2220f74f8..968de2f55a 100644
--- a/src/Java/gtPlusPlus/core/util/Utils.java
+++ b/src/Java/gtPlusPlus/core/util/Utils.java
@@ -485,7 +485,10 @@ public class Utils {
return true;
}
- public static File getMcDir() {
+ public static File getMcDir() {
+ if (Minecraft.getMinecraft() == null) {
+ return new File("testdir");
+ }
if ((MinecraftServer.getServer() != null) && MinecraftServer.getServer().isDedicatedServer()) {
return new File(".");
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
index 425606dd8e..486cda42f9 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
@@ -1,26 +1,18 @@
package gtPlusPlus.core.util.minecraft;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
-
-import net.minecraft.block.Block;
-import net.minecraft.init.Items;
-import net.minecraft.inventory.IInventory;
-import net.minecraft.item.Item;
-import net.minecraft.item.Item.ToolMaterial;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.StatCollector;
-
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
-import gtPlusPlus.GTplusplus;
-import gtPlusPlus.api.objects.GregtechException;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.api.objects.minecraft.BlockPos;
@@ -38,6 +30,14 @@ import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration;
+import net.minecraft.block.Block;
+import net.minecraft.init.Items;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.Item;
+import net.minecraft.item.Item.ToolMaterial;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -50,9 +50,18 @@ public class ItemUtils {
public static ItemStack getSimpleStack(final Block x) {
return simpleMetaStack(Item.getItemFromBlock(x), 0, 1);
}
+
- public static ItemStack getSimpleStack(final Block x, int meta) {
- return simpleMetaStack(Item.getItemFromBlock(x), meta, 1);
+ public static ItemStack getSimpleStack(final Block x, int i) {
+ if (i == 0) {
+ return getSimpleStack(x, i, 1);
+ }
+
+ return getSimpleStack(x, 0, i);
+ }
+
+ public static ItemStack getSimpleStack(final Block x, int meta, int i) {
+ return simpleMetaStack(Item.getItemFromBlock(x), meta, i);
}
public static ItemStack getSimpleStack(final Item x, final int i) {
@@ -315,7 +324,7 @@ public class ItemUtils {
return returnValue;
}
Logger.INFO("Failed to find `" + oredictName + "` in OD.");
- return getErrorStack(amount);
+ return getErrorStack(amount, oredictName+" x"+amount);
//return getItemStackOfAmountFromOreDictNoBroken(mTemp, amount);
}
@@ -366,8 +375,7 @@ public class ItemUtils {
public static ItemStack getGregtechDust(final Materials material, final int amount) {
final ItemStack returnValue = GT_OreDictUnificator.get(OrePrefixes.dust, material, 1L);
if (returnValue != null) {
- if ((returnValue.getItem().getClass() != ModItems.AAA_Broken.getClass())
- || (returnValue.getItem() != ModItems.AAA_Broken)) {
+ if (ItemUtils.checkForInvalidItems(returnValue)) {
return returnValue.copy();
}
}
@@ -600,25 +608,40 @@ public class ItemUtils {
public static String getArrayStackNames(final ItemStack[] aStack) {
String itemNames = "Item Array: ";
- for (final ItemStack alph : aStack) {
-
+ int aPos = 0;
+ for (final ItemStack alph : aStack) {
+ if (alph == null) {
+ continue;
+ }
if (alph != null) {
final String temp = itemNames;
- itemNames = temp + ", " + alph.getDisplayName() + " x" + alph.stackSize;
- } else {
- final String temp = itemNames;
- itemNames = temp + ", " + "null" + " x" + "0";
+ itemNames = temp + (aPos > 0 ? ", " : "") + alph.getDisplayName() + " x" + alph.stackSize;
+ aPos++;
}
}
return itemNames;
}
public static String[] getArrayStackNamesAsArray(final ItemStack[] aStack) {
- final String[] itemNames = {};
+ final String[] itemNames = aStack == null ? new String[] {} : new String[aStack.length];
+ Logger.INFO(""+aStack.length);
+
+ if (aStack == null || aStack.length < 1) {
+ return itemNames;
+ }
+
int arpos = 0;
- for (final ItemStack alph : aStack) {
+ for (final ItemStack alph : aStack) {
+ if (alph == null) {
+ continue;
+ }
+ try {
itemNames[arpos] = alph.getDisplayName();
arpos++;
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
}
return itemNames;
@@ -762,23 +785,23 @@ public class ItemUtils {
if (aGtStack == null) {
Logger.INFO(
"Failed to find `" + mPrefix + MaterialUtils.getMaterialName(mMat) + "` in OD. [Prefix Search]");
- return getErrorStack(mAmount);
+ return getErrorStack(mAmount, (mPrefix.toString()+MaterialUtils.getMaterialName(mMat)+" x"+mAmount));
} else {
return aGtStack;
}
}
- public static ItemStack getErrorStack(int mAmount) {
- //System.exit(1);
- try {
- //new GregtechException("Logging - [Issue #999]");
- }
- catch (Throwable t) {
- t.printStackTrace();
- }
+ public static ItemStack getErrorStack(int mAmount) {
+ return getErrorStack(mAmount, null);
+ }
- return getSimpleStack(ModItems.AAA_Broken, mAmount);
- //return null;
+ public static ItemStack getErrorStack(int mAmount, String aName) {
+ ItemStack g = getSimpleStack(ModItems.AAA_Broken, 1);
+ NBTUtils.setString(g, "Lore", EnumChatFormatting.RED+aName);
+ if (aName != null) {
+ NBTUtils.setBookTitle(g, EnumChatFormatting.YELLOW+"Maybe Alkalus should know about this");
+ }
+ return g;
}
public static ItemStack[] getStackOfAllOreDictGroup(String oredictname) {
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java
index d4f217bbfd..dde785cee6 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java
@@ -10,18 +10,22 @@ import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.common.GT_Proxy;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
-import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.chunk.Chunk;
public class PollutionUtils {
private static boolean mIsPollutionEnabled = true;
+ private static Method mAddPollution;
+ private static Method mAddPollution2;
+
+ private static Method mGetPollution;
+ private static Method mGetPollution2;
+
static {
if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) {
mIsPollutionEnabled = mPollution();
- }
- else {
+ } else {
mIsPollutionEnabled = false;
}
}
@@ -42,65 +46,123 @@ public class PollutionUtils {
public static boolean addPollution(IGregTechTileEntity te, int pollutionValue) {
if (mIsPollutionEnabled)
- try {
- Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
- if (GT_Pollution != null) {
- Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class);
- if (addPollution != null) {
- addPollution.invoke(null, te, pollutionValue);
- return true;
+ try {
+ if (te == null) {
+ return false;
}
+ if (mAddPollution != null) {
+ mAddPollution.invoke(null, te, pollutionValue);
+ }
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null) {
+ Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class);
+ if (addPollution != null) {
+ mAddPollution = addPollution;
+ addPollution.invoke(null, te, pollutionValue);
+ return true;
+ }
+ }
+ } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
}
- } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- }
return false;
}
- public static int getPollution(IGregTechTileEntity te) {
+ public static boolean addPollution(IHasWorldObjectAndCoords aTileOfSomeSort, int pollutionValue) {
if (mIsPollutionEnabled)
- try {
- Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
- if (GT_Pollution != null) {
- Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class);
- if (addPollution != null) {
- return (int) addPollution.invoke(null, te);
+ try {
+ if (aTileOfSomeSort == null) {
+ return false;
}
+ IHasWorldObjectAndCoords j = (IHasWorldObjectAndCoords) aTileOfSomeSort;
+ Chunk c = j.getWorld().getChunkFromBlockCoords(j.getXCoord(), j.getZCoord());
+ return addPollution(c, pollutionValue);
+ } catch (SecurityException | IllegalArgumentException e) {
}
- } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- }
- return 0;
+ return false;
}
- public static boolean addPollution(Object aTileOfSomeSort, int pollutionValue) {
+ public static boolean addPollution(Chunk aChunk, int pollutionValue) {
if (mIsPollutionEnabled)
- try {
- Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
- if (GT_Pollution != null) {
- Method addPollution = GT_Pollution.getMethod("addPollution", Chunk.class, int.class);
- if (addPollution != null) {
- IHasWorldObjectAndCoords j = (IHasWorldObjectAndCoords) aTileOfSomeSort;
- if (j != null) {
- Chunk c = j.getWorld().getChunkFromBlockCoords(j.getXCoord(), j.getZCoord());
- addPollution.invoke(null, c, pollutionValue);
+ try {
+ if (aChunk == null) {
+ return false;
+ }
+ if (mAddPollution2 != null) {
+ mAddPollution2.invoke(null, aChunk, pollutionValue);
+ return true;
+ }
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null) {
+ Method addPollution = GT_Pollution.getMethod("addPollution", Chunk.class, int.class);
+ if (addPollution != null) {
+ mAddPollution2 = addPollution;
+ mAddPollution2.invoke(null, aChunk, pollutionValue);
return true;
- } else {
- TileEntity t = (TileEntity) aTileOfSomeSort;
- if (t != null) {
- Chunk c = t.getWorldObj().getChunkFromBlockCoords(t.xCoord, t.zCoord);
- addPollution.invoke(null, c, pollutionValue);
- return true;
- }
}
-
}
+ } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
}
- } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- }
return false;
+ }
+
+ public static boolean removePollution(IGregTechTileEntity te, int pollutionValue) {
+ return addPollution(te, -pollutionValue);
+ }
+
+ public static boolean removePollution(IHasWorldObjectAndCoords aTileOfSomeSort, int pollutionValue) {
+ return addPollution(aTileOfSomeSort, -pollutionValue);
+ }
+
+ public static boolean removePollution(Chunk aChunk, int pollutionValue) {
+ return addPollution(aChunk, -pollutionValue);
+ }
+
+ public static int getPollution(IGregTechTileEntity te) {
+ if (mIsPollutionEnabled)
+ try {
+ if (te == null) {
+ return 0;
+ }
+ if (mGetPollution != null) {
+ mGetPollution.invoke(null, te);
+ }
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null) {
+ Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class);
+ if (addPollution != null) {
+ mGetPollution = addPollution;
+ return (int) addPollution.invoke(null, te);
+ }
+ }
+ } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
+ }
+ return 0;
+ }
+ public static int getPollution(Chunk te) {
+ if (mIsPollutionEnabled)
+ try {
+ if (te == null) {
+ return 0;
+ }
+ if (mGetPollution2 != null) {
+ mGetPollution2.invoke(null, te);
+ }
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null) {
+ Method addPollution = GT_Pollution.getMethod("getPollution", Chunk.class);
+ if (addPollution != null) {
+ mGetPollution2 = addPollution;
+ return (int) addPollution.invoke(null, te);
+ }
+ }
+ } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
+ | IllegalArgumentException | InvocationTargetException e) {
+ }
+ return 0;
}
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java
index afba320fe7..635239bbfc 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java
@@ -1,76 +1,3 @@
package gtPlusPlus.core.util.minecraft.gregtech.recipehandlers;
-import java.lang.reflect.Method;
-
-import net.minecraft.item.ItemStack;
-
-import gregtech.api.util.GT_ModHandler;
-
-import gtPlusPlus.api.objects.Logger;
-import gtPlusPlus.core.lib.CORE;
-
-public final class GregtechRecipe {
-
- public LibraryProxy ourProxy;
- public GregtechRecipe(){
- Logger.INFO("Initializing a recipe handler for different versions of Gregtech 5.");
- try {
- if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){
- this.ourProxy = new LibProxy1();
- Logger.INFO("Selecting GT 5.7/5.8 Recipe Set");
- }
- if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){
- this.ourProxy = new LibProxy2();
- Logger.INFO("Selecting GT 5.9 Recipe Set");
- }
- } catch (final NoSuchMethodException e) {
- this.ourProxy = null;
- }
- }
-
- public boolean addSmeltingAndAlloySmeltingRecipe(final ItemStack aInput, final ItemStack aOutput) {
- Logger.WARNING("Adding a GT Furnace/Alloy Smelter Recipe"+"| Input:"+aInput.getDisplayName()+" | Output:"+aOutput.getDisplayName()+" |");
- return this.ourProxy.addSmeltingAndAlloySmeltingRecipe(aInput, aOutput);
- }
-
-}
-
-abstract class LibraryProxy { // can also be interface unless you want to have common code here
- abstract public boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput);
-}
-
-class LibProxy1 extends LibraryProxy {
- final Method m1;
-
- public LibProxy1() throws NoSuchMethodException {
- this.m1 = GT_ModHandler.class.getDeclaredMethod("addSmeltingAndAlloySmeltingRecipe", ItemStack.class, ItemStack.class);
- }
-
- @Override
- public boolean addSmeltingAndAlloySmeltingRecipe(final ItemStack aInput, final ItemStack aOutput) {
- try {
- //Logger.INFO("Trying with Gt 5.7/5.8 Method.");
- return (boolean) this.m1.invoke(null, aInput, aOutput);
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- }
-}
-
-class LibProxy2 extends LibraryProxy {
- final Method m2;
-
- public LibProxy2() throws NoSuchMethodException {
- this.m2 = GT_ModHandler.class.getDeclaredMethod("addSmeltingAndAlloySmeltingRecipe", ItemStack.class, ItemStack.class, boolean.class);
- }
-
- @Override
- public boolean addSmeltingAndAlloySmeltingRecipe(final ItemStack aInput, final ItemStack aOutput) {
- try {
- //Logger.INFO("Trying with Gt 5.9 Method.");
- return (boolean) this.m2.invoke(null, aInput, aOutput, true);
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- }
-} \ No newline at end of file
+public final class GregtechRecipe {} \ No newline at end of file