Reworked EntityPlayerMP.openGui to hopefully be more compatible with PlayerAPI

This commit is contained in:
LexManos 2012-03-26 04:27:34 -07:00
parent dd17ebd009
commit 2230ca7c54
2 changed files with 68 additions and 66 deletions

View File

@ -1,17 +1,21 @@
--- ../src_base/minecraft_server/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
@@ -3,6 +3,10 @@
@@ -3,6 +3,14 @@
import java.util.Iterator;
import java.util.List;
+import net.minecraft.src.forge.ArmorProperties;
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.IGuiHandler;
+import net.minecraft.src.forge.ISpecialArmor;
+import net.minecraft.src.forge.MinecraftForge;
+import net.minecraft.src.forge.NetworkMod;
+import net.minecraft.src.forge.packets.PacketOpenGUI;
+
public abstract class EntityPlayer extends EntityLiving
{
/** Inventory of the player */
@@ -172,6 +176,7 @@
@@ -172,6 +180,7 @@
}
else
{
@ -19,7 +23,7 @@
if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0)
{
this.updateItemUse(var1, 5);
@@ -361,6 +366,10 @@
@@ -361,6 +370,10 @@
*/
protected void closeScreen()
{
@ -30,7 +34,7 @@
this.craftingInventory = this.inventorySlots;
}
@@ -544,7 +553,16 @@
@@ -544,7 +557,16 @@
*/
public EntityItem dropOneItem()
{
@ -48,7 +52,7 @@
}
/**
@@ -609,10 +627,18 @@
@@ -609,10 +631,18 @@
/**
* Returns how strong the player is against the specified block at this moment
@ -68,7 +72,7 @@
float var3 = var2;
int var4 = EnchantmentHelper.getEfficiencyModifier(this.inventory);
@@ -908,7 +934,11 @@
@@ -908,7 +938,11 @@
par2 = 1 + par2 >> 1;
}
@ -81,7 +85,7 @@
par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
this.addExhaustion(par1DamageSource.getHungerDamage());
this.health -= par2;
@@ -939,6 +969,10 @@
@@ -939,6 +973,10 @@
*/
public void useCurrentItemOnEntity(Entity par1Entity)
{
@ -92,7 +96,7 @@
if (!par1Entity.interact(this))
{
ItemStack var2 = this.getCurrentEquippedItem();
@@ -969,7 +1003,9 @@
@@ -969,7 +1007,9 @@
*/
public void destroyCurrentEquippedItem()
{
@ -102,7 +106,7 @@
}
/**
@@ -998,6 +1034,16 @@
@@ -998,6 +1038,16 @@
*/
public void attackTargetEntityWithCurrentItem(Entity par1Entity)
{
@ -119,7 +123,7 @@
if (par1Entity.canAttackWithItem())
{
int var2 = this.inventory.getDamageVsEntity(par1Entity);
@@ -1136,6 +1182,12 @@
@@ -1136,6 +1186,12 @@
*/
public EnumStatus sleepInBedAt(int par1, int par2, int par3)
{
@ -132,7 +136,7 @@
if (!this.worldObj.isRemote)
{
if (this.isPlayerSleeping() || !this.isEntityAlive())
@@ -1717,4 +1769,16 @@
@@ -1717,4 +1773,45 @@
{
return !this.capabilities.isFlying;
}
@ -147,5 +151,34 @@
+ * @param Y Y Position
+ * @param Z Z Position
+ */
+ public void openGui(BaseMod mod, int ID, World world, int x, int y, int z){}
+ public void openGui(BaseMod mod, int ID, World world, int x, int y, int z)
+ {
+ if (!(this instanceof EntityPlayerMP))
+ {
+ return;
+ }
+
+ EntityPlayerMP player = (EntityPlayerMP)this;
+
+ if (!(mod instanceof NetworkMod))
+ {
+ return;
+ }
+
+ IGuiHandler handler = MinecraftForge.getGuiHandler(mod);
+ if (handler != null)
+ {
+ Container container = handler.getGuiContainer(ID, player, world, x, y, z);
+ if (container != null)
+ {
+ player.realGetNextWidowId();
+ player.closeCraftingGui();
+ PacketOpenGUI pkt = new PacketOpenGUI(player.getCurrentWindowIdField(), MinecraftForge.getModID((NetworkMod)mod), ID, x, y, z);
+ player.playerNetServerHandler.sendPacket(pkt.getPacket());
+ craftingInventory = container;
+ craftingInventory.windowId = player.getCurrentWindowIdField();
+ craftingInventory.onCraftGuiOpened(player);
+ }
+ }
+ }
}

View File

@ -1,100 +1,69 @@
--- ../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
@@ -5,6 +5,10 @@
import java.util.List;
import java.util.Set;
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
{
@@ -551,6 +555,7 @@
@@ -551,6 +551,7 @@
public void displayWorkbenchGUI(int par1, int par2, int par3)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 1, "Crafting", 9));
this.craftingInventory = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3);
this.craftingInventory.windowId = this.currentWindowId;
@@ -560,6 +565,7 @@
@@ -560,6 +561,7 @@
public void displayGUIEnchantment(int par1, int par2, int par3)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 4, "Enchanting", 9));
this.craftingInventory = new ContainerEnchantment(this.inventory, this.worldObj, par1, par2, par3);
this.craftingInventory.windowId = this.currentWindowId;
@@ -572,6 +578,7 @@
@@ -572,6 +574,7 @@
public void displayGUIChest(IInventory par1IInventory)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 0, par1IInventory.getInvName(), par1IInventory.getSizeInventory()));
this.craftingInventory = new ContainerChest(this.inventory, par1IInventory);
this.craftingInventory.windowId = this.currentWindowId;
@@ -584,6 +591,7 @@
@@ -584,6 +587,7 @@
public void displayGUIFurnace(TileEntityFurnace par1TileEntityFurnace)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 2, par1TileEntityFurnace.getInvName(), par1TileEntityFurnace.getSizeInventory()));
this.craftingInventory = new ContainerFurnace(this.inventory, par1TileEntityFurnace);
this.craftingInventory.windowId = this.currentWindowId;
@@ -596,6 +604,7 @@
@@ -596,6 +600,7 @@
public void displayGUIDispenser(TileEntityDispenser par1TileEntityDispenser)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 3, par1TileEntityDispenser.getInvName(), par1TileEntityDispenser.getSizeInventory()));
this.craftingInventory = new ContainerDispenser(this.inventory, par1TileEntityDispenser);
this.craftingInventory.windowId = this.currentWindowId;
@@ -608,6 +617,7 @@
@@ -608,6 +613,7 @@
public void displayGUIBrewingStand(TileEntityBrewingStand par1TileEntityBrewingStand)
{
this.getNextWidowId();
+ closeCraftingGui(); //TODO: This is a bug fix for chests staying open in SMP
+ closeCraftingGui(); //NOTE: This is a bug fix for chests staying open in SMP
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 5, par1TileEntityBrewingStand.getInvName(), par1TileEntityBrewingStand.getSizeInventory()));
this.craftingInventory = new ContainerBrewingStand(this.inventory, par1TileEntityBrewingStand);
this.craftingInventory.windowId = this.currentWindowId;
@@ -797,4 +807,38 @@
@@ -797,4 +803,18 @@
EntityTracker var2 = this.mcServer.getEntityTracker(this.dimension);
var2.sendPacketToTrackedPlayersAndTrackedEntity(this, new Packet18Animation(par1Entity, 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
+ /* These functions are added to have compatibility with PlayerAPI.
+ * If Divisor does not implement these functions, it is his fault,
+ * these are specifically the functions he told me to use and would be guaranteed to be in PAPI.
+ */
+ @Override
+ public void openGui(BaseMod mod, int ID, World world, int x, int y, int z)
+ public final void realGetNextWidowId()
+ {
+ 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);
+ }
+ }
+ getNextWidowId();
+ }
+
+ public final int getCurrentWindowIdField()
+ {
+ return currentWindowId;
+ }
}