diff --git a/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java b/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java new file mode 100644 index 0000000000..a654b7a8c7 --- /dev/null +++ b/forge/forge_client/src/net/minecraft/src/forge/IGuiHandler.java @@ -0,0 +1,21 @@ +package net.minecraft.src.forge; + +import net.minecraft.src.EntityPlayerSP; +import net.minecraft.src.GuiScreen; +import net.minecraft.src.World; + +public interface IGuiHandler +{ + /** + * Returns a GuiScreen to be displayed to the user. This is client side + * + * @param ID The Gui ID Number + * @param player The player viewing the Gui + * @param world The current world + * @param X X Position + * @param Y Y Position + * @param Z Z Position + * @return A GuiScreen to be displayed to the user, null if none. + */ + public GuiScreen getGuiScreen(int ID, EntityPlayerSP player, World world, int X, int Y, int Z); +} diff --git a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java index 9052238ae6..81cbf5ef56 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java @@ -53,6 +53,12 @@ public class PacketHandlerClient implements IPacketHandler pkt.readData(data); onModIDs((PacketModIDs)pkt); break; + + case ForgePacket.OPEN_GUI: + pkt = new PacketOpenGUI(); + pkt.readData(data); + onOpenGui((PacketOpenGUI)pkt); + break; } } catch(IOException e) @@ -192,4 +198,20 @@ public class PacketHandlerClient implements IPacketHandler } //TODO: Display error/confirmation screen } + + /** + * Handles opening the Gui for the player. + * + * @param pkt The Open Gui Packet + */ + private void onOpenGui(PacketOpenGUI pkt) + { + NetworkMod mod = MinecraftForge.getModByID(pkt.ModID); + if (mod != null) + { + EntityPlayerSP player = (EntityPlayerSP)ModLoader.getMinecraftInstance().thePlayer; + player.openGui(mod, pkt.GuiID, player.worldObj, pkt.X, pkt.Y, pkt.Z); + player.craftingInventory.windowId = pkt.WindowID; + } + } } diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index e1544c3bf2..f5b0d3b456 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -368,6 +368,7 @@ public class ForgeHooks { } public static Hashtable networkMods = new Hashtable(); + public static Hashtable guiHandlers = new Hashtable(); public static final int majorVersion=0; public static final int minorVersion=0; diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index 9df81093ac..e669f3c71d 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -906,6 +906,28 @@ public class MinecraftForge { } return ret.toArray(new NetworkMod[0]); } + + /** + * Sets the GuiHandler associated with a mod. + * + * @param mod The mod + * @param handler The Gui Handler + */ + public static void setGuiHandler(BaseMod mod, IGuiHandler handler) + { + ForgeHooks.guiHandlers.put(mod, handler); + } + + /** + * Gets the GuiHandler associated with a mod + * + * @param mod The mod + * @return The handler, or null if none associated. + */ + public static IGuiHandler getGuiHandler(BaseMod mod) + { + return ForgeHooks.guiHandlers.get(mod); + } static diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java new file mode 100644 index 0000000000..f2939e42fa --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java @@ -0,0 +1,54 @@ +package net.minecraft.src.forge.packets; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class PacketOpenGUI extends ForgePacket +{ + public int WindowID; + public int ModID; + public int GuiID; + public int X; + public int Y; + public int Z; + + public PacketOpenGUI(){} + public PacketOpenGUI(int window, int mod, int id, int x, int y, int z) + { + WindowID = window; + ModID = mod; + GuiID = id; + X = x; + Y = y; + Z = z; + } + + @Override + public void writeData(DataOutputStream data) throws IOException + { + data.writeInt(WindowID); + data.writeInt(ModID); + data.writeInt(GuiID); + data.writeInt(X); + data.writeInt(Y); + data.writeInt(Z); + } + + @Override + public void readData(DataInputStream data) throws IOException + { + WindowID = data.readInt(); + ModID = data.readInt(); + GuiID = data.readInt(); + X = data.readInt(); + Y = data.readInt(); + Z = data.readInt(); + } + + @Override + public int getID() + { + return ForgePacket.OPEN_GUI; + } +} diff --git a/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java b/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java new file mode 100644 index 0000000000..d4ab037225 --- /dev/null +++ b/forge/forge_server/src/net/minecraft/src/forge/IGuiHandler.java @@ -0,0 +1,21 @@ +package net.minecraft.src.forge; + +import net.minecraft.src.Container; +import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.World; + +public interface IGuiHandler +{ + /** + * Returns a Container to be displayed to the user. This is server side + * + * @param ID The Gui ID Number + * @param player The player viewing the Gui + * @param world The current world + * @param X X Position + * @param Y Y Position + * @param Z Z Position + * @return A GuiScreen to be displayed to the user, null if none. + */ + public Container getGuiContainer(int ID, EntityPlayerMP player, World world, int X, int Y, int Z); +} diff --git a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch index 8974e31334..48b4148181 100644 --- a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch @@ -140,3 +140,20 @@ if (!worldObj.isRemote) { if (isPlayerSleeping() || !isEntityAlive()) +@@ -1473,4 +1545,16 @@ + experience = entityplayer.experience; + score = entityplayer.score; + } ++ ++ /** ++ * Opens a Gui for the player. ++ * ++ * @param mod The mod associated with the gui ++ * @param ID The ID number for the Gui ++ * @param world The World ++ * @param X X Position ++ * @param Y Y Position ++ * @param Z Z Position ++ */ ++ public void openGui(BaseMod mod, int ID, World world, int X, int Y, int Z){} + } diff --git a/forge/patches/minecraft/net/minecraft/src/EntityPlayerSP.java.patch b/forge/patches/minecraft/net/minecraft/src/EntityPlayerSP.java.patch new file mode 100644 index 0000000000..a4747b95a7 --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/EntityPlayerSP.java.patch @@ -0,0 +1,40 @@ +--- ../src_base/minecraft/net/minecraft/src/EntityPlayerSP.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft/net/minecraft/src/EntityPlayerSP.java 0000-00-00 00:00:00.000000000 -0000 +@@ -2,6 +2,8 @@ + + import java.util.Random; + import net.minecraft.client.Minecraft; ++import net.minecraft.src.forge.IGuiHandler; ++import net.minecraft.src.forge.MinecraftForge; + + public class EntityPlayerSP extends EntityPlayer + { +@@ -474,4 +476,28 @@ + experienceTotal = i; + experienceLevel = j; + } ++ ++ /** ++ * Opens a Gui for the player. ++ * ++ * @param mod The mod associated with the gui ++ * @param ID The ID number for the Gui ++ * @param world The World ++ * @param X X Position ++ * @param Y Y Position ++ * @param Z Z Position ++ */ ++ @Override ++ public void openGui(BaseMod mod, int ID, World world, int X, int Y, int Z) ++ { ++ IGuiHandler handler = MinecraftForge.getGuiHandler(mod); ++ if (handler != null) ++ { ++ GuiScreen screen = handler.getGuiScreen(ID, this, world, X, Y, Z); ++ if (screen != null) ++ { ++ mc.displayGuiScreen(screen); ++ } ++ } ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch index 748565193a..6f784ae02b 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch @@ -150,3 +150,20 @@ if (!worldObj.isRemote) { if (isPlayerSleeping() || !isEntityAlive()) +@@ -1353,4 +1428,16 @@ + experience = entityplayer.experience; + score = entityplayer.score; + } ++ ++ /** ++ * Opens a Gui for the player. ++ * ++ * @param mod The mod associated with the gui ++ * @param ID The ID number for the Gui ++ * @param world The World ++ * @param X X Position ++ * @param Y Y Position ++ * @param Z Z Position ++ */ ++ public void openGui(BaseMod mod, int ID, World world, int X, int Y, int Z){} + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayerMP.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayerMP.java.patch index fb0401f7c8..2d207b352e 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayerMP.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayerMP.java.patch @@ -1,6 +1,17 @@ --- ../src_base/minecraft_server/net/minecraft/src/EntityPlayerMP.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/EntityPlayerMP.java 0000-00-00 00:00:00.000000000 -0000 -@@ -405,6 +405,7 @@ +@@ -2,6 +2,10 @@ + + import java.util.*; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.src.forge.IGuiHandler; ++import net.minecraft.src.forge.MinecraftForge; ++import net.minecraft.src.forge.NetworkMod; ++import net.minecraft.src.forge.packets.PacketOpenGUI; + + public class EntityPlayerMP extends EntityPlayer + implements ICrafting +@@ -405,6 +409,7 @@ public void displayWorkbenchGUI(int i, int j, int k) { getNextWidowId(); @@ -8,7 +19,7 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 1, "Crafting", 9)); craftingInventory = new ContainerWorkbench(inventory, worldObj, i, j, k); craftingInventory.windowId = currentWindowId; -@@ -414,6 +415,7 @@ +@@ -414,6 +419,7 @@ public void displayGUIEnchantment(int i, int j, int k) { getNextWidowId(); @@ -16,7 +27,7 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 4, "Enchanting", 9)); craftingInventory = new ContainerEnchantment(inventory, worldObj, i, j, k); craftingInventory.windowId = currentWindowId; -@@ -423,6 +425,7 @@ +@@ -423,6 +429,7 @@ public void displayGUIChest(IInventory iinventory) { getNextWidowId(); @@ -24,7 +35,7 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 0, iinventory.getInvName(), iinventory.getSizeInventory())); craftingInventory = new ContainerChest(inventory, iinventory); craftingInventory.windowId = currentWindowId; -@@ -432,6 +435,7 @@ +@@ -432,6 +439,7 @@ public void displayGUIFurnace(TileEntityFurnace tileentityfurnace) { getNextWidowId(); @@ -32,7 +43,7 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 2, tileentityfurnace.getInvName(), tileentityfurnace.getSizeInventory())); craftingInventory = new ContainerFurnace(inventory, tileentityfurnace); craftingInventory.windowId = currentWindowId; -@@ -441,6 +445,7 @@ +@@ -441,6 +449,7 @@ public void displayGUIDispenser(TileEntityDispenser tileentitydispenser) { getNextWidowId(); @@ -40,7 +51,7 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 3, tileentitydispenser.getInvName(), tileentitydispenser.getSizeInventory())); craftingInventory = new ContainerDispenser(inventory, tileentitydispenser); craftingInventory.windowId = currentWindowId; -@@ -450,6 +455,7 @@ +@@ -450,6 +459,7 @@ public void displayGUIBrewingStand(TileEntityBrewingStand tileentitybrewingstand) { getNextWidowId(); @@ -48,3 +59,42 @@ playerNetServerHandler.sendPacket(new Packet100OpenWindow(currentWindowId, 5, tileentitybrewingstand.getInvName(), tileentitybrewingstand.getSizeInventory())); craftingInventory = new ContainerBrewingStand(inventory, tileentitybrewingstand); craftingInventory.windowId = currentWindowId; +@@ -613,4 +623,38 @@ + EntityTracker entitytracker = mcServer.getEntityTracker(dimension); + entitytracker.sendPacketToTrackedPlayersAndTrackedEntity(this, new Packet18Animation(entity, 7)); + } ++ ++ /** ++ * Opens a Gui for the player. ++ * ++ * @param mod The mod associated with the gui ++ * @param ID The ID number for the Gui ++ * @param world The World ++ * @param X X Position ++ * @param Y Y Position ++ * @param Z Z Position ++ */ ++ @Override ++ public void openGui(BaseMod mod, int ID, World world, int X, int Y, int Z) ++ { ++ if (!(mod instanceof NetworkMod)) ++ { ++ return; ++ } ++ IGuiHandler handler = MinecraftForge.getGuiHandler(mod); ++ if (handler != null) ++ { ++ Container container = handler.getGuiContainer(ID, this, world, X, Y, Z); ++ if (container != null) ++ { ++ getNextWidowId(); ++ closeCraftingGui(); ++ PacketOpenGUI pkt = new PacketOpenGUI(currentWindowId, MinecraftForge.getModID((NetworkMod)mod), ID, X, Y, Z); ++ playerNetServerHandler.sendPacket(pkt.getPacket()); ++ craftingInventory = container; ++ craftingInventory.windowId = currentWindowId; ++ craftingInventory.onCraftGuiOpened(this); ++ } ++ } ++ } + }