Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Some help for galacticraft compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobata committed May 3, 2013
1 parent e7ea5eb commit 9cf81f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/minecraft/invtweaks/InvTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
40 changes: 31 additions & 9 deletions src/minecraft/invtweaks/InvTweaksModCompatibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContainerSection, List<Slot>> getSpecialContainerSlots(GuiScreen guiScreen, Container container) {
Class<? extends GuiScreen> 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<ContainerSection, List<Slot>>) m.invoke(guiScreen);
} catch (Exception e) {
// TODO: Do something here to tell mod authors they're doing it wrong.
if(guiScreen != null) {
Class<? extends GuiScreen> 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<ContainerSection, List<Slot>>) m.invoke(guiScreen);
} catch (Exception e) {
// TODO: Do something here to tell mod authors they're doing it wrong.
}
}
}
}
Expand All @@ -170,13 +185,20 @@ public Map<ContainerSection, List<Slot>> 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) {
Expand Down
3 changes: 2 additions & 1 deletion src/minecraft/invtweaks/InvTweaksObfuscation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9cf81f7

Please sign in to comment.