more careful ae2 check and obs field check

This commit is contained in:
GlodBlock committed 2022-05-10 22:36:28 +08:00
1 parent 170e8c4a3b
commit 39b089805c
6 files changed
+76 -18

No files matched your search

@@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -36,9 +37,9 @@ public class Ae2Reflect {
static {
try {
fInventory_container = reflectField(InventoryCrafting.class, "eventHandler");
fInventory_width = reflectField(InventoryCrafting.class, "inventoryWidth");
fInventory_stackList = reflectField(InventoryCrafting.class, "stackList");
fInventory_container = reflectField(InventoryCrafting.class, "eventHandler", "field_70465_c", "c");
fInventory_width = reflectField(InventoryCrafting.class, "inventoryWidth", "field_70464_b", "b");
fInventory_stackList = reflectField(InventoryCrafting.class, "stackList", "field_70466_a", "a");
fAEContainer_upgradeable = reflectField(ContainerUpgradeable.class, "upgradeable");
mItemSlot_setExtractable = reflectMethod(ItemSlot.class, "setExtractable", boolean.class);
mTracker_isBusy = reflectMethod(MultiCraftingTracker.class, "isBusy", int.class);
@@ -54,8 +55,17 @@ public class Ae2Reflect {
return m;
}
public static Field reflectField(Class<?> owner, String name) throws NoSuchFieldException {
Field f = owner.getDeclaredField(name);
public static Field reflectField(Class<?> owner, String ...names) throws NoSuchFieldException {
Field f = null;
for (String name : names) {
try {
f = owner.getDeclaredField(name);
if (f != null) break;
}
catch (NoSuchFieldException ignore) {
}
}
if (f == null) throw new NoSuchFieldException("Can't find field from " + Arrays.toString(names));
f.setAccessible(true);
return f;
}
@@ -144,8 +154,8 @@ public class Ae2Reflect {
fGuiMEMonitorable_configSrc = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "configSrc");
fGuiMEMonitorable_craftingStatusBtn = Ae2Reflect.reflectField(GuiFCBaseMonitor.class, "craftingStatusBtn");
fGuiCPUStatus_icon = Ae2Reflect.reflectField(GuiCraftingStatus.class, "myIcon");
fGuiContainer_guiLeft = Ae2Reflect.reflectField(GuiContainer.class, "guiLeft");
fGuiContainer_guiTop = Ae2Reflect.reflectField(GuiContainer.class, "guiTop");
fGuiContainer_guiLeft = Ae2Reflect.reflectField(GuiContainer.class, "guiLeft", "field_147003_i", "i");
fGuiContainer_guiTop = Ae2Reflect.reflectField(GuiContainer.class, "guiTop", "field_147009_r", "r");
fCPU_cpu = Ae2Reflect.reflectField(CraftingCPURecord.class, "cpu");
fCPU_myName = Ae2Reflect.reflectField(CraftingCPURecord.class, "myName");
fCPU_processors = Ae2Reflect.reflectField(CraftingCPURecord.class, "processors");
@@ -1,23 +1,66 @@
package com.glodblock.github.util;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.core.AEConfig;
import appeng.core.localization.ButtonToolTips;
import cpw.mods.fml.common.Loader;
import java.lang.reflect.Field;
public final class ModAndClassUtil {
public static boolean GT5 = false;
public static boolean GT6 = false;
public static boolean isDoubleButton;
public static boolean isSaveText;
public static boolean isSearchStringTooltip;
public static boolean isCraftStatus;
public static boolean isSearchBar;
public static void init() {
try {
ActionItems x = ActionItems.DOUBLE;
Field d = AEConfig.instance.getClass().getDeclaredField("preserveSearchBar");
if (d == null) isSearchBar = false;
isSearchBar = true;
} catch (NoSuchFieldException e) {
isSearchBar = false;
}
try {
Field d = ActionItems.class.getDeclaredField("DOUBLE");
if (d == null) isDoubleButton = false;
isDoubleButton = true;
} catch (Exception e) {
} catch (NoSuchFieldException e) {
isDoubleButton = false;
}
try {
Field d = Settings.class.getDeclaredField("SAVE_SEARCH");
if (d == null) isSaveText = false;
isSaveText = true;
} catch (NoSuchFieldException e) {
isSaveText = false;
}
try {
Field d = ButtonToolTips.class.getDeclaredField("SearchStringTooltip");
if (d == null) isSearchStringTooltip = false;
isSearchStringTooltip = true;
} catch (NoSuchFieldException e) {
isSearchStringTooltip = false;
}
try {
Field d = Settings.class.getDeclaredField("CRAFTING_STATUS");
if (d == null) isCraftStatus = false;
isCraftStatus = true;
} catch (NoSuchFieldException e) {
isCraftStatus = false;
}
if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi"))
GT5 = true;
if (Loader.isModLoaded("gregapi") && Loader.isModLoaded("gregapi_post"))