aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus
diff options
context:
space:
mode:
authormiozune <miozune@gmail.com>2023-02-16 17:43:54 +0900
committerGitHub <noreply@github.com>2023-02-16 09:43:54 +0100
commit6d1ce9ee20fc0bdb7dda2d7066a8c3474e4d1050 (patch)
tree549c66a1105bd76e157a9adceea3614b52787a4a /src/main/java/gtPlusPlus
parentf387766d71209d3e9eb8837ae3592f2b8f5838e1 (diff)
downloadGT5-Unofficial-6d1ce9ee20fc0bdb7dda2d7066a8c3474e4d1050.tar.gz
GT5-Unofficial-6d1ce9ee20fc0bdb7dda2d7066a8c3474e4d1050.tar.bz2
GT5-Unofficial-6d1ce9ee20fc0bdb7dda2d7066a8c3474e4d1050.zip
Remove reflections against BW (#544)
Diffstat (limited to 'src/main/java/gtPlusPlus')
-rw-r--r--src/main/java/gtPlusPlus/xmod/bartworks/BW_Utils.java81
1 files changed, 10 insertions, 71 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/bartworks/BW_Utils.java b/src/main/java/gtPlusPlus/xmod/bartworks/BW_Utils.java
index fabcc2b6c8..650ecfa55e 100644
--- a/src/main/java/gtPlusPlus/xmod/bartworks/BW_Utils.java
+++ b/src/main/java/gtPlusPlus/xmod/bartworks/BW_Utils.java
@@ -1,88 +1,27 @@
package gtPlusPlus.xmod.bartworks;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Map;
import net.minecraft.item.ItemStack;
+import com.github.bartimaeusnek.bartworks.system.material.BW_NonMeta_MaterialItems;
+import com.github.bartimaeusnek.bartworks.system.material.Werkstoff;
+import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader;
import gregtech.api.enums.OrePrefixes;
-import gtPlusPlus.core.lib.LoadedMods;
-import gtPlusPlus.core.util.reflect.ReflectionUtils;
public class BW_Utils {
- private static final Method sName;
- private static final Method sGet;
- private static final Class<?> sClassBW_NonMeta_MaterialItems;
- private static final Class<?> Werkstoff;
- private static final Class<?> WerkstoffLoader;
- private static final Map<Short, ?> werkstoffHashMap;
- private static final Method getCorrespondingItemStackUnsafe;
-
- static {
- sName = ReflectionUtils.getMethod(Enum.class, "name");
- sClassBW_NonMeta_MaterialItems = ReflectionUtils
- .getClass("com.github.bartimaeusnek.bartworks.system.material.BW_NonMeta_MaterialItems");
- sGet = ReflectionUtils.getMethod(sClassBW_NonMeta_MaterialItems, "get", long.class, Object[].class);
- Werkstoff = ReflectionUtils.getClass("com.github.bartimaeusnek.bartworks.system.material.Werkstoff");
- WerkstoffLoader = ReflectionUtils
- .getClass("com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader");
- Field fieldWerkstoffHashMap = ReflectionUtils.getField(Werkstoff, "werkstoffHashMap");
- werkstoffHashMap = ReflectionUtils.getFieldValue(fieldWerkstoffHashMap);
- getCorrespondingItemStackUnsafe = ReflectionUtils
- .getMethod(WerkstoffLoader, "getCorrespondingItemStackUnsafe", OrePrefixes.class, Werkstoff, int.class);
- }
-
- public enum NonMeta_MaterialItem {
- Depleted_Tiberium_1,
- Depleted_Tiberium_2,
- Depleted_Tiberium_4,
- TiberiumCell_1,
- TiberiumCell_2,
- TiberiumCell_4,
- TheCoreCell,
- Depleted_TheCoreCell;
- }
-
- public static ItemStack getBW_NonMeta_MaterialItems(NonMeta_MaterialItem aItem, long aAmount) {
- if (sClassBW_NonMeta_MaterialItems != null && sClassBW_NonMeta_MaterialItems.isEnum()) {
- for (Object obj : sClassBW_NonMeta_MaterialItems.getEnumConstants()) {
- try {
- if (aItem.name().equals(ReflectionUtils.invokeNonBool(obj, sName, new Object[] {}))) {
- return ((ItemStack) ReflectionUtils
- .invokeNonBool(obj, sGet, new Object[] { aAmount, new Object[] {} })).copy();
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- }
- return null;
- }
-
public static ArrayList<ItemStack> getAll(int aStackSize) {
- ArrayList<ItemStack> aItems = new ArrayList<ItemStack>();
- aItems.add(getBW_NonMeta_MaterialItems(NonMeta_MaterialItem.TiberiumCell_1, aStackSize));
- aItems.add(getBW_NonMeta_MaterialItems(NonMeta_MaterialItem.TiberiumCell_2, aStackSize));
- aItems.add(getBW_NonMeta_MaterialItems(NonMeta_MaterialItem.TiberiumCell_4, aStackSize));
- aItems.add(getBW_NonMeta_MaterialItems(NonMeta_MaterialItem.TheCoreCell, aStackSize));
+ ArrayList<ItemStack> aItems = new ArrayList<>();
+ aItems.add(BW_NonMeta_MaterialItems.TiberiumCell_1.get(aStackSize));
+ aItems.add(BW_NonMeta_MaterialItems.TiberiumCell_2.get(aStackSize));
+ aItems.add(BW_NonMeta_MaterialItems.TiberiumCell_4.get(aStackSize));
+ aItems.add(BW_NonMeta_MaterialItems.TheCoreCell.get(aStackSize));
return aItems;
}
public static ItemStack getCorrespondingItemStack(OrePrefixes orePrefixes, short werkstoffID, int amount) {
- if (LoadedMods.BartWorks) {
- if (werkstoffHashMap != null) {
- Object werkstoff = werkstoffHashMap.get(werkstoffID);
- if (werkstoff != null) {
- return (ItemStack) ReflectionUtils.invokeNonBool(
- null,
- getCorrespondingItemStackUnsafe,
- new Object[] { orePrefixes, werkstoff, amount });
- }
- }
- }
- return null;
+ return WerkstoffLoader
+ .getCorrespondingItemStackUnsafe(orePrefixes, Werkstoff.werkstoffHashMap.get(werkstoffID), amount);
}
}