From 4e912932719ca854a1524e7b77ebd9350435a1bc Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 6 Aug 2012 20:45:37 -0700 Subject: [PATCH] More work, moved over packet stuff, need to change everything to use new NetworkMod system --- common/forge_at.cfg | 3 + .../minecraftforge/common}/IGuiHandler.java | 5 +- .../minecraftforge/common}/ISpawnHandler.java | 2 +- .../minecraftforge/common/ISpecialArmor.java | 4 +- .../common}/IThrowableEntity.java | 2 +- .../minecraftforge}/packets/ForgePacket.java | 9 +- .../packets/PacketEntitySpawn.java | 9 +- .../packets/PacketEntityTrack.java | 2 +- .../packets/PacketHandlerBase.java | 2 +- .../packets/PacketOpenGUI.java | 2 +- .../src/forge/packets/PacketMissingMods.java | 21 -- .../src/forge/packets/PacketModList.java | 116 --------- .../net/minecraft/src/EntityPlayer.java.patch | 231 +++++++++++++++++- .../net/minecraft/src/RenderItem.java.patch | 2 +- 14 files changed, 250 insertions(+), 160 deletions(-) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge/common}/IGuiHandler.java (78%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge/common}/ISpawnHandler.java (95%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge/common}/IThrowableEntity.java (94%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge}/packets/ForgePacket.java (83%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge}/packets/PacketEntitySpawn.java (94%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge}/packets/PacketEntityTrack.java (96%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge}/packets/PacketHandlerBase.java (94%) rename {forge_common/net/minecraft/src/forge => common/net/minecraftforge}/packets/PacketOpenGUI.java (97%) delete mode 100644 forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java delete mode 100644 forge_common/net/minecraft/src/forge/packets/PacketModList.java diff --git a/common/forge_at.cfg b/common/forge_at.cfg index 6e919b114..ca370a477 100644 --- a/common/forge_at.cfg +++ b/common/forge_at.cfg @@ -33,3 +33,6 @@ public ayp.c # soundPoolStreaming public ayp.d # soundPoolMusic # EntityLiving public jv.aM # carryoverDamage +# EntityPlayerMP +public gt.bO()V # incrementWindowID() +public gt.cq # currentWindowId diff --git a/forge_common/net/minecraft/src/forge/IGuiHandler.java b/common/net/minecraftforge/common/IGuiHandler.java similarity index 78% rename from forge_common/net/minecraft/src/forge/IGuiHandler.java rename to common/net/minecraftforge/common/IGuiHandler.java index 9f0bd13d3..4d606f0c3 100644 --- a/forge_common/net/minecraft/src/forge/IGuiHandler.java +++ b/common/net/minecraftforge/common/IGuiHandler.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge; +package net.minecraftforge.common; import net.minecraft.src.EntityPlayer; import net.minecraft.src.World; @@ -9,6 +9,9 @@ public interface IGuiHandler * Returns a Container to be displayed to the user. * On the client side, this needs to return a instance of GuiScreen * On the server side, this needs to return a instance of Container + * + * On the client, the player will always be a instance of EntityPlayerSP + * On the server, the player will always be a instance of EntityPlayerMP * * @param ID The Gui ID Number * @param player The player viewing the Gui diff --git a/forge_common/net/minecraft/src/forge/ISpawnHandler.java b/common/net/minecraftforge/common/ISpawnHandler.java similarity index 95% rename from forge_common/net/minecraft/src/forge/ISpawnHandler.java rename to common/net/minecraftforge/common/ISpawnHandler.java index 5c1fd7b70..c4e148fb3 100644 --- a/forge_common/net/minecraft/src/forge/ISpawnHandler.java +++ b/common/net/minecraftforge/common/ISpawnHandler.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge; +package net.minecraftforge.common; import java.io.DataInputStream; import java.io.DataOutputStream; diff --git a/common/net/minecraftforge/common/ISpecialArmor.java b/common/net/minecraftforge/common/ISpecialArmor.java index 46764fbe2..b440029be 100644 --- a/common/net/minecraftforge/common/ISpecialArmor.java +++ b/common/net/minecraftforge/common/ISpecialArmor.java @@ -157,10 +157,10 @@ public interface ISpecialArmor } if (stack.stackSize <= 0) { - if (entity instanceof EntityPlayer) + /*if (entity instanceof EntityPlayer) { stack.onItemDestroyedByUse((EntityPlayer)entity); - } + }*/ inventory[prop.Slot] = null; } } diff --git a/forge_common/net/minecraft/src/forge/IThrowableEntity.java b/common/net/minecraftforge/common/IThrowableEntity.java similarity index 94% rename from forge_common/net/minecraft/src/forge/IThrowableEntity.java rename to common/net/minecraftforge/common/IThrowableEntity.java index e24b540d9..02c25cc2e 100644 --- a/forge_common/net/minecraft/src/forge/IThrowableEntity.java +++ b/common/net/minecraftforge/common/IThrowableEntity.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge; +package net.minecraftforge.common; import net.minecraft.src.Entity; diff --git a/forge_common/net/minecraft/src/forge/packets/ForgePacket.java b/common/net/minecraftforge/packets/ForgePacket.java similarity index 83% rename from forge_common/net/minecraft/src/forge/packets/ForgePacket.java rename to common/net/minecraftforge/packets/ForgePacket.java index 17c2fef1e..04af74140 100644 --- a/forge_common/net/minecraft/src/forge/packets/ForgePacket.java +++ b/common/net/minecraftforge/packets/ForgePacket.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge.packets; +package net.minecraftforge.packets; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -8,17 +8,14 @@ import java.util.List; import net.minecraft.src.Packet; import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.forge.ForgeHooks; public abstract class ForgePacket { //Forge Packet ID Constants. public static final int FORGE_ID = 0x040E9B47; //"Forge".hashCode(); public static final int SPAWN = 1; - public static final int MODLIST = 2; - public static final int MOD_MISSING = 3; - public static final int OPEN_GUI = 5; - public static final int TRACK = 6; + public static final int OPEN_GUI = 2; + public static final int TRACK = 3; public Packet getPacket() { diff --git a/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java b/common/net/minecraftforge/packets/PacketEntitySpawn.java similarity index 94% rename from forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java rename to common/net/minecraftforge/packets/PacketEntitySpawn.java index 6e0341396..4f90c95ca 100644 --- a/forge_common/net/minecraft/src/forge/packets/PacketEntitySpawn.java +++ b/common/net/minecraftforge/packets/PacketEntitySpawn.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge.packets; +package net.minecraftforge.packets; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -8,10 +8,9 @@ import net.minecraft.src.Entity; import net.minecraft.src.EntityLiving; import net.minecraft.src.DataWatcher; import net.minecraft.src.MathHelper; -import net.minecraft.src.forge.ISpawnHandler; -import net.minecraft.src.forge.IThrowableEntity; -import net.minecraft.src.forge.MinecraftForge; -import net.minecraft.src.forge.NetworkMod; +import net.minecraftforge.common.ISpawnHandler; +import net.minecraftforge.common.IThrowableEntity; +import net.minecraftforge.common.MinecraftForge; public class PacketEntitySpawn extends ForgePacket { diff --git a/forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java b/common/net/minecraftforge/packets/PacketEntityTrack.java similarity index 96% rename from forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java rename to common/net/minecraftforge/packets/PacketEntityTrack.java index 6763c7cb2..9d84f8c3c 100644 --- a/forge_common/net/minecraft/src/forge/packets/PacketEntityTrack.java +++ b/common/net/minecraftforge/packets/PacketEntityTrack.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge.packets; +package net.minecraftforge.packets; import java.io.DataInputStream; import java.io.DataOutputStream; diff --git a/forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java b/common/net/minecraftforge/packets/PacketHandlerBase.java similarity index 94% rename from forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java rename to common/net/minecraftforge/packets/PacketHandlerBase.java index f19d3c2d3..fdfd32b60 100644 --- a/forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java +++ b/common/net/minecraftforge/packets/PacketHandlerBase.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge.packets; +package net.minecraftforge.packets; import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet; diff --git a/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java b/common/net/minecraftforge/packets/PacketOpenGUI.java similarity index 97% rename from forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java rename to common/net/minecraftforge/packets/PacketOpenGUI.java index 7b5a1d9bc..a33f71fc9 100644 --- a/forge_common/net/minecraft/src/forge/packets/PacketOpenGUI.java +++ b/common/net/minecraftforge/packets/PacketOpenGUI.java @@ -1,4 +1,4 @@ -package net.minecraft.src.forge.packets; +package net.minecraftforge.packets; import java.io.DataInputStream; import java.io.DataOutputStream; diff --git a/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java b/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java deleted file mode 100644 index 3edb0b311..000000000 --- a/forge_common/net/minecraft/src/forge/packets/PacketMissingMods.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class PacketMissingMods extends PacketModList -{ - - public PacketMissingMods(boolean server) - { - super(!server); - } - - @Override - public int getID() - { - return ForgePacket.MOD_MISSING; - } - -} diff --git a/forge_common/net/minecraft/src/forge/packets/PacketModList.java b/forge_common/net/minecraft/src/forge/packets/PacketModList.java deleted file mode 100644 index 302cfb57e..000000000 --- a/forge_common/net/minecraft/src/forge/packets/PacketModList.java +++ /dev/null @@ -1,116 +0,0 @@ -package net.minecraft.src.forge.packets; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.EOFException; -import java.io.IOException; -import java.util.Hashtable; -import java.util.List; -import java.util.Map.Entry; - -public class PacketModList extends ForgePacket -{ - private boolean isServer = false; - public String[] Mods; - public Hashtable ModIDs = new Hashtable(); - public int Length = -1; - public boolean has4096 = false; - - public PacketModList(boolean server) - { - isServer = server; - } - - @Override - public void writeData(DataOutputStream data) throws IOException - { - if (!isServer) - { - data.writeInt(Mods.length); - for (String mod : Mods) - { - data.writeUTF(mod); - } - } - else - { - data.writeInt(ModIDs.size()); - for (Entry entry : ModIDs.entrySet()) - { - data.writeInt(entry.getKey()); - data.writeUTF(entry.getValue()); - } - } - data.writeBoolean(true); - } - - @Override - public void readData(DataInputStream data) throws IOException - { - if (isServer) - { - Length = data.readInt(); - if (Length >= 0) - { - Mods = new String[Length]; - for (int x = 0; x < Length; x++) - { - Mods[x] = data.readUTF(); - } - } - } - else - { - Length = data.readInt(); - for (int x = 0; x < Length; x++) - { - ModIDs.put(data.readInt(), data.readUTF()); - } - } - - try - { - has4096 = data.readBoolean(); - } - catch (EOFException e) - { - has4096 = false; - } - } - - @Override - public int getID() - { - return ForgePacket.MODLIST; - } - - @Override - public String toString(boolean full) - { - if (full) - { - StringBuilder ret = new StringBuilder(); - ret.append(toString()).append('\n'); - if (Mods != null) - { - for (String mod : Mods) - { - ret.append(" " + mod + '\n'); - } - } - else if (ModIDs.size() != 0) - { - for (Entry mod : ModIDs.entrySet()) - { - ret.append(String.format(" %03d ", mod.getKey()) + mod.getValue() + '\n'); - } - } - return ret.toString(); - } - else - { - return toString(); - } - } - -} diff --git a/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch b/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch index 7ee586e0a..c48915aff 100644 --- a/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch +++ b/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch @@ -1,15 +1,44 @@ --- ../src_base/minecraft/net/minecraft/src/EntityPlayer.java +++ ../src_work/minecraft/net/minecraft/src/EntityPlayer.java -@@ -2,6 +2,8 @@ +@@ -2,6 +2,11 @@ import java.util.Iterator; import java.util.List; + +import net.minecraftforge.common.ForgeHooks; ++import net.minecraftforge.common.IGuiHandler; ++import net.minecraftforge.common.ISpecialArmor.ArmorProperties; ++import net.minecraftforge.common.MinecraftForge; public abstract class EntityPlayer extends EntityLiving implements ICommandSender { -@@ -673,13 +675,21 @@ +@@ -207,6 +212,7 @@ + + if (var1 == this.itemInUse) + { ++ itemInUse.getItem().onUsingItemTick(itemInUse, this, itemInUseCount); + if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0) + { + this.updateItemUse(var1, 5); +@@ -607,7 +613,16 @@ + */ + public EntityItem dropOneItem() + { +- return this.dropPlayerItemWithRandomChoice(this.inventory.decrStackSize(this.inventory.currentItem, 1), false); ++ ItemStack stack = inventory.getCurrentItem(); ++ if (stack == null) ++ { ++ return null; ++ } ++ if (stack.getItem().onDroppedByPlayer(stack, this)) ++ { ++ return dropPlayerItemWithRandomChoice(inventory.decrStackSize(inventory.currentItem, 1), false); ++ } ++ return null; + } + + /** +@@ -673,13 +688,21 @@ /** * Returns how strong the player is against the specified block at this moment @@ -34,7 +63,42 @@ { var2 += (float)(var3 * var3 + 1); } -@@ -1055,7 +1065,9 @@ +@@ -972,12 +995,22 @@ + */ + protected void damageEntity(DamageSource par1DamageSource, int par2) + { ++ par2 = ForgeHooks.onEntityLivingHurt(this, par1DamageSource, par2); ++ if (par2 == 0) ++ { ++ return; ++ } ++ + if (!par1DamageSource.isUnblockable() && this.isBlocking()) + { + par2 = 1 + par2 >> 1; + } + +- par2 = this.applyArmorCalculations(par1DamageSource, par2); ++ par2 = ArmorProperties.ApplyArmor(this, inventory.armorInventory, par1DamageSource, par2); ++ if (par2 <= 0) ++ { ++ return; ++ } + par2 = this.applyPotionDamageCalculations(par1DamageSource, par2); + this.addExhaustion(par1DamageSource.getHungerDamage()); + this.health -= par2; +@@ -1012,6 +1045,10 @@ + + public boolean interactWith(Entity par1Entity) + { ++ if (!ForgeHooks.onEntityInteract(this, par1Entity, false)) ++ { ++ return false; ++ } + if (par1Entity.interact(this)) + { + return true; +@@ -1055,7 +1092,9 @@ */ public void destroyCurrentEquippedItem() { @@ -44,3 +108,164 @@ } /** +@@ -1084,6 +1123,15 @@ + */ + public void attackTargetEntityWithCurrentItem(Entity par1Entity) + { ++ if (!ForgeHooks.onEntityInteract(this, par1Entity, true)) ++ { ++ return; ++ } ++ ItemStack stack = getCurrentEquippedItem(); ++ if (stack != null && stack.getItem().onLeftClickEntity(stack, this, par1Entity)) ++ { ++ return; ++ } + if (par1Entity.canAttackWithItem()) + { + int var2 = this.inventory.getDamageVsEntity(par1Entity); +@@ -1226,6 +1274,11 @@ + */ + public EnumStatus sleepInBedAt(int par1, int par2, int par3) + { ++ EnumStatus customSleep = ForgeHooks.sleepInBedAt(this, par1, par2, par3); ++ if (customSleep != null) ++ { ++ return customSleep; ++ } + if (!this.worldObj.isRemote) + { + if (this.isPlayerSleeping() || !this.isEntityAlive()) +@@ -1265,6 +1318,11 @@ + { + int var9 = this.worldObj.getBlockMetadata(par1, par2, par3); + int var5 = BlockBed.getDirection(var9); ++ Block block = Block.blocksList[worldObj.getBlockId(par1, par2, par3)]; ++ if (block != null) ++ { ++ var5 = block.getBedDirection(worldObj, par1, par2, par3); ++ } + float var10 = 0.5F; + float var7 = 0.5F; + +@@ -1334,11 +1392,12 @@ + this.resetHeight(); + ChunkCoordinates var4 = this.playerLocation; + ChunkCoordinates var5 = this.playerLocation; +- +- if (var4 != null && this.worldObj.getBlockId(var4.posX, var4.posY, var4.posZ) == Block.bed.blockID) +- { +- BlockBed.setBedOccupied(this.worldObj, var4.posX, var4.posY, var4.posZ, false); +- var5 = BlockBed.getNearestEmptyChunkCoordinates(this.worldObj, var4.posX, var4.posY, var4.posZ, 0); ++ Block block = (var4 == null ? null : Block.blocksList[worldObj.getBlockId(var4.posX, var4.posY, var4.posZ)]); ++ ++ if (var4 != null && block != null && block.isBed(worldObj, var4.posX, var4.posY, var4.posZ, this)) ++ { ++ block.setBedOccupied(this.worldObj, var4.posX, var4.posY, var4.posZ, this, false); ++ var5 = block.getBedSpawnPosition(worldObj, var4.posX, var4.posY, var4.posZ, this); + + if (var5 == null) + { +@@ -1375,7 +1434,9 @@ + */ + private boolean isInBed() + { +- return this.worldObj.getBlockId(this.playerLocation.posX, this.playerLocation.posY, this.playerLocation.posZ) == Block.bed.blockID; ++ ChunkCoordinates c = playerLocation; ++ int blockID = worldObj.getBlockId(c.posX, c.posY, c.posZ); ++ return Block.blocksList[blockID] != null && Block.blocksList[blockID].isBed(worldObj, c.posX, c.posY, c.posZ, this); + } + + /** +@@ -1389,14 +1450,15 @@ + var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ - 3 >> 4); + var2.loadChunk(par1ChunkCoordinates.posX - 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); + var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); +- +- if (par0World.getBlockId(par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ) != Block.bed.blockID) ++ ChunkCoordinates c = par1ChunkCoordinates; ++ Block block = Block.blocksList[par0World.getBlockId(c.posX, c.posY, c.posZ)]; ++ if (block == null || !block.isBed(par0World, c.posX, c.posY, c.posZ, null)) + { + return null; + } + else + { +- ChunkCoordinates var3 = BlockBed.getNearestEmptyChunkCoordinates(par0World, par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ, 0); ++ ChunkCoordinates var3 = block.getBedSpawnPosition(par0World, c.posX, c.posY, c.posZ, null); + return var3; + } + } +@@ -1408,8 +1470,11 @@ + { + if (this.playerLocation != null) + { +- int var1 = this.worldObj.getBlockMetadata(this.playerLocation.posX, this.playerLocation.posY, this.playerLocation.posZ); +- int var2 = BlockBed.getDirection(var1); ++ int x = playerLocation.posX; ++ int y = playerLocation.posY; ++ int z = playerLocation.posZ; ++ Block block = Block.blocksList[worldObj.getBlockId(x, y, z)]; ++ int var2 = (block == null ? 0 : block.getBedDirection(worldObj, x, y, z)); + + switch (var2) + { +@@ -1699,6 +1764,7 @@ + return 101; + } + } ++ var3 = par1ItemStack.getItem().getIconIndex(par1ItemStack, par2, this, itemInUse, itemInUseCount); + } + + return var3; +@@ -1919,4 +1985,50 @@ + { + return this.theInventoryEnderChest; + } ++ ++ /** ++ * 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) ++ { ++ if (this instanceof EntityPlayerSP) ++ { ++ IGuiHandler handler = MinecraftForge.getGuiHandler(mod, true); ++ if (handler != null) ++ { ++ GuiScreen screen = (GuiScreen)handler.getGuiElement(ID, this, world, x, y, z); ++ if (screen != null) ++ { ++ ModLoader.getMinecraftInstance().displayGuiScreen(screen); ++ } ++ } ++ } ++ else if (this instanceof EntityPlayerMP) ++ { ++ EntityPlayerMP player = (EntityPlayerMP)this; ++ IGuiHandler handler = MinecraftForge.getGuiHandler(mod, false); ++ ++ if (handler != null) ++ { ++ Container container = (Container)handler.getGuiElement(ID, player, world, x, y, z); ++ if (container != null) ++ { ++ player.incrementWindowID(); ++ player.closeInventory(); ++ PacketOpenGUI pkt = new PacketOpenGUI(player.currentWindowId, MinecraftForge.getModID((NetworkMod)mod), ID, x, y, z); ++ player.serverForThisPlayer.sendPacket(pkt.getPacket()); ++ craftingInventory = container; ++ craftingInventory.windowId = player.currentWindowId; ++ craftingInventory.addCraftingToCrafters(player); ++ } ++ } ++ } ++ } + } diff --git a/patches/minecraft/net/minecraft/src/RenderItem.java.patch b/patches/minecraft/net/minecraft/src/RenderItem.java.patch index a553ea62f..ee54cfd7e 100644 --- a/patches/minecraft/net/minecraft/src/RenderItem.java.patch +++ b/patches/minecraft/net/minecraft/src/RenderItem.java.patch @@ -53,7 +53,7 @@ - for (var15 = 0; var15 <= 1; ++var15) + this.loadTexture(Item.itemsList[var10.itemID].getTextureFile()); + -+ for (var15 = 0; var15 <= var10.getItem().getRenderPasses(var10.getItemDamage(); ++var15) ++ for (var15 = 0; var15 <= var10.getItem().getRenderPasses(var10.getItemDamage()); ++var15) { + this.random.setSeed(187L); //Fixes Vanilla bug where layers would not render aligns properly. var16 = var10.getItem().getIconFromDamageForRenderPass(var10.getItemDamage(), var15);