From 9cf81f794b97956c1af3cb1243eb59c82dfd4a3a Mon Sep 17 00:00:00 2001 From: Kobata Date: Thu, 2 May 2013 23:16:03 -0400 Subject: [PATCH] Some help for galacticraft compatibility. --- src/minecraft/invtweaks/InvTweaks.java | 4 ++ .../invtweaks/InvTweaksModCompatibility.java | 40 ++++++++++++++----- .../invtweaks/InvTweaksObfuscation.java | 3 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/minecraft/invtweaks/InvTweaks.java b/src/minecraft/invtweaks/InvTweaks.java index 4bdb58f1..bc79e028 100644 --- a/src/minecraft/invtweaks/InvTweaks.java +++ b/src/minecraft/invtweaks/InvTweaks.java @@ -142,6 +142,10 @@ public void onTickInGUI(GuiScreen guiScreen) { // Right-click is always true on initial open of GUI. // Ignore it to prevent erroneous trigger of shortcuts. mouseWasDown = true; + log.info(guiScreen.getClass().getName()); + if(guiScreen instanceof GuiContainer) { + log.info(((GuiContainer) guiScreen).inventorySlots.getClass().getName()); + } } handleShortcuts(guiScreen); diff --git a/src/minecraft/invtweaks/InvTweaksModCompatibility.java b/src/minecraft/invtweaks/InvTweaksModCompatibility.java index 4e35ed80..eb1f2613 100644 --- a/src/minecraft/invtweaks/InvTweaksModCompatibility.java +++ b/src/minecraft/invtweaks/InvTweaksModCompatibility.java @@ -135,16 +135,31 @@ public boolean isSpecialInventory(GuiScreen guiScreen) { } } + /** + * Returns true if the screen is the inventory screen, despite not being a GuiInventory. + * + * @param guiScreen + */ + public boolean isStandardInventory(GuiScreen guiScreen) { + // TODO: API stuff to allow this. + if (isExact(guiScreen, "micdoodle8.mods.galacticraft.core.client.gui.GCCoreGuiInventory")) { + return true; + } + return false; + } + @SuppressWarnings("unchecked") public Map> getSpecialContainerSlots(GuiScreen guiScreen, Container container) { - Class clazz = guiScreen.getClass(); - if (isAPIClass(clazz)) { - Method m = getAnnotatedMethod(clazz, new Class[]{ContainerGUI.ContainerSectionCallback.class, InventoryGUI.ContainerSectionCallback.class}, 0, Map.class); - if (m != null) { - try { - return (Map>) m.invoke(guiScreen); - } catch (Exception e) { - // TODO: Do something here to tell mod authors they're doing it wrong. + if(guiScreen != null) { + Class clazz = guiScreen.getClass(); + if (isAPIClass(clazz)) { + Method m = getAnnotatedMethod(clazz, new Class[]{ContainerGUI.ContainerSectionCallback.class, InventoryGUI.ContainerSectionCallback.class}, 0, Map.class); + if (m != null) { + try { + return (Map>) m.invoke(guiScreen); + } catch (Exception e) { + // TODO: Do something here to tell mod authors they're doing it wrong. + } } } } @@ -170,13 +185,20 @@ public Map> getSpecialContainerSlots(GuiScreen guiS result.put(ContainerSection.INVENTORY, slots.subList(9, 45)); result.put(ContainerSection.INVENTORY_NOT_HOTBAR, slots.subList(9, 36)); result.put(ContainerSection.INVENTORY_HOTBAR, slots.subList(36, 45)); + } else if (isExact(container, "micdoodle8.mods.galacticraft.core.inventory.GCCoreContainerPlayer")) { + result.put(ContainerSection.CRAFTING_OUT, slots.subList(0, 1)); + result.put(ContainerSection.CRAFTING_IN, slots.subList(1, 5)); + result.put(ContainerSection.ARMOR, slots.subList(5, 9)); + result.put(ContainerSection.INVENTORY, slots.subList(9, 45)); + result.put(ContainerSection.INVENTORY_NOT_HOTBAR, slots.subList(9, 36)); + result.put(ContainerSection.INVENTORY_HOTBAR, slots.subList(36, 45)); } return result; } - private static boolean isExact(GuiScreen guiScreen, String className) { + private static boolean isExact(Object guiScreen, String className) { try { return guiScreen.getClass().getName().equals(className); } catch (Exception e) { diff --git a/src/minecraft/invtweaks/InvTweaksObfuscation.java b/src/minecraft/invtweaks/InvTweaksObfuscation.java index c164cc99..b136085d 100644 --- a/src/minecraft/invtweaks/InvTweaksObfuscation.java +++ b/src/minecraft/invtweaks/InvTweaksObfuscation.java @@ -524,7 +524,8 @@ public boolean isStandardInventory(GuiScreen guiScreen) { || isGuiBeacon(guiScreen) || isGuiHopper(guiScreen) || (isGuiInventoryCreative(guiScreen) - && getSlots(getContainer(asGuiContainer(guiScreen))).size() == 46); + && getSlots(getContainer(asGuiContainer(guiScreen))).size() == 46) + || mods.isStandardInventory(guiScreen); } public boolean isGuiContainer(Object o) { // GuiContainer (abstract class)