Exposed TileEntityData packet to TileEntities. And added helper sender function.

This commit is contained in:
LexManos 2012-04-19 15:41:11 -07:00
parent 722fe597b8
commit bb7eaf867f
6 changed files with 124 additions and 25 deletions

View file

@ -16,6 +16,7 @@ import net.minecraft.src.ModLoader;
import net.minecraft.src.NetworkManager; import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.Packet131MapData; import net.minecraft.src.Packet131MapData;
import net.minecraft.src.Packet132TileEntityData;
import net.minecraft.src.World; import net.minecraft.src.World;
import java.util.*; import java.util.*;
@ -1164,6 +1165,32 @@ public class MinecraftForge
sendPacket(net, pkt); sendPacket(net, pkt);
} }
/**
* Helper function for wrapping and sending a Packet132TileEntityData packet,
* useful so we don't have to edit the packet class itself to add the constructor on the client side.
*
* @param net The manager to send the packet to
* @param x Position X
* @param y Position Y
* @param z Position Z
* @param action Action ID
* @param par1 Custom Parameter 1
* @param par2 Custom Parameter 2
* @param par3 Custom Parameter 3
*/
public static void sendTileEntityPacket(NetworkManager net, int x, short y, int z, byte action, int par1, int par2, int par3)
{
Packet132TileEntityData pkt = new Packet132TileEntityData();
pkt.xPosition = x;
pkt.yPosition = y;
pkt.zPosition = z;
pkt.actionType = action;
pkt.customParam1 = par1;
pkt.customParam2 = par2;
pkt.customParam3 = par3;
sendPacket(net, pkt);
}
private static int isClient = -1; private static int isClient = -1;
public static boolean isClient() public static boolean isClient()
{ {

View file

@ -35,8 +35,9 @@ public class mod_MinecraftForge extends NetworkMod
ForgeHooks.networkMods.put(x++, (NetworkMod)mod); ForgeHooks.networkMods.put(x++, (NetworkMod)mod);
} }
} }
//Add 131 to C->S list //Add 131 & 132 to C->S list
((Set)ModLoader.getPrivateValue(Packet.class, null, 3)).add(131); ((Set)ModLoader.getPrivateValue(Packet.class, null, 3)).add(131);
((Set)ModLoader.getPrivateValue(Packet.class, null, 3)).add(132);
} }
} }

View file

@ -1,8 +1,11 @@
--- ../src_base/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
@@ -15,6 +15,10 @@ @@ -14,7 +14,13 @@
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
+import java.util.logging.Level;
+
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
+import net.minecraft.src.forge.ForgeHooks; +import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.MessageManager; +import net.minecraft.src.forge.MessageManager;
@ -11,7 +14,7 @@
public class NetClientHandler extends NetHandler public class NetClientHandler extends NetHandler
{ {
@@ -46,6 +50,8 @@ @@ -46,6 +52,8 @@
this.mc = par1Minecraft; this.mc = par1Minecraft;
Socket var4 = new Socket(InetAddress.getByName(par2Str), par3); Socket var4 = new Socket(InetAddress.getByName(par2Str), par3);
this.netManager = new NetworkManager(var4, "Client", this); this.netManager = new NetworkManager(var4, "Client", this);
@ -20,7 +23,7 @@
} }
/** /**
@@ -73,6 +79,30 @@ @@ -73,6 +81,30 @@
this.mc.thePlayer.entityId = par1Packet1Login.protocolVersion; this.mc.thePlayer.entityId = par1Packet1Login.protocolVersion;
this.currentServerMaxPlayers = par1Packet1Login.maxPlayers; this.currentServerMaxPlayers = par1Packet1Login.maxPlayers;
((PlayerControllerMP)this.mc.playerController).setCreative(par1Packet1Login.serverMode == 1); ((PlayerControllerMP)this.mc.playerController).setCreative(par1Packet1Login.serverMode == 1);
@ -51,7 +54,7 @@
ModLoader.serverConnect(this, par1Packet1Login); ModLoader.serverConnect(this, par1Packet1Login);
} }
@@ -545,8 +575,12 @@ @@ -545,8 +577,12 @@
public void handleChat(Packet3Chat par1Packet3Chat) public void handleChat(Packet3Chat par1Packet3Chat)
{ {
@ -66,7 +69,7 @@
} }
public void handleAnimation(Packet18Animation par1Packet18Animation) public void handleAnimation(Packet18Animation par1Packet18Animation)
@@ -633,7 +667,19 @@ @@ -633,7 +669,19 @@
} }
else if (par1Packet2Handshake.username.equals("-")) else if (par1Packet2Handshake.username.equals("-"))
{ {
@ -87,7 +90,7 @@
} }
else else
{ {
@@ -646,7 +692,19 @@ @@ -646,7 +694,19 @@
if (var6.equalsIgnoreCase("ok")) if (var6.equalsIgnoreCase("ok"))
{ {
@ -108,7 +111,27 @@
} }
else else
{ {
@@ -1012,6 +1070,10 @@ @@ -939,6 +999,19 @@
{
((TileEntityMobSpawner)var2).setMobID(EntityList.getStringFromID(par1Packet132TileEntityData.customParam1));
}
+ else if (var2 != null)
+ {
+ var2.onDataPacket(netManager, par1Packet132TileEntityData);
+ }
+ else
+ {
+ Packet132TileEntityData pkt = par1Packet132TileEntityData;
+ ModLoader.getLogger().log(Level.WARNING, String.format(
+ "Received a TileEntityData packet for a location that did not have a TileEntity: (%d, %d, %d) %d: %d, %d, %d",
+ pkt.xPosition, pkt.yPosition, pkt.zPosition,
+ pkt.actionType,
+ pkt.customParam1, pkt.customParam2, pkt.customParam3));
+ }
}
}
@@ -1012,6 +1085,10 @@
{ {
ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).func_28171_a(par1Packet131MapData.itemData); ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).func_28171_a(par1Packet131MapData.itemData);
} }
@ -119,7 +142,7 @@
else else
{ {
System.out.println("Unknown itemid: " + par1Packet131MapData.uniqueID); System.out.println("Unknown itemid: " + par1Packet131MapData.uniqueID);
@@ -1114,5 +1176,40 @@ @@ -1114,5 +1191,40 @@
public void handleCustomPayload(Packet250CustomPayload var1) public void handleCustomPayload(Packet250CustomPayload var1)
{ {
ModLoader.receivePacket(var1); ModLoader.receivePacket(var1);

View file

@ -1,6 +1,6 @@
--- ../src_base/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000
@@ -216,4 +216,13 @@ @@ -216,4 +216,24 @@
addMapping(TileEntityEnchantmentTable.class, "EnchantTable"); addMapping(TileEntityEnchantmentTable.class, "EnchantTable");
addMapping(TileEntityEndPortal.class, "Airportal"); addMapping(TileEntityEndPortal.class, "Airportal");
} }
@ -13,4 +13,15 @@
+ { + {
+ return true; + return true;
+ } + }
+
+ /**
+ * Called when you receive a TileEntityData packet for the location this
+ * TileEntity is currently in. On the client, the NetworkManager will always
+ * be the remote server. On the server, it will be whomever is responsible for
+ * sending the packet.
+ *
+ * @param net The NetworkManager the packet originated from
+ * @param pkt The data packet
+ */
+ public void onDataPacket(NetworkManager net, Packet132TileEntityData pkt){}
} }

View file

@ -1,6 +1,11 @@
--- ../src_base/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/NetServerHandler.java 0000-00-00 00:00:00.000000000 -0000
@@ -6,6 +6,9 @@ @@ -2,10 +2,14 @@
import java.util.ArrayList;
import java.util.Random;
+import java.util.logging.Level;
import java.util.logging.Logger;
import cpw.mods.fml.server.FMLServerHandler; import cpw.mods.fml.server.FMLServerHandler;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -10,7 +15,7 @@
public class NetServerHandler extends NetHandler implements ICommandListener public class NetServerHandler extends NetHandler implements ICommandListener
{ {
@@ -19,7 +22,7 @@ @@ -19,7 +23,7 @@
public boolean connectionClosed = false; public boolean connectionClosed = false;
/** Reference to the MinecraftServer object. */ /** Reference to the MinecraftServer object. */
@ -19,7 +24,7 @@
/** Reference to the EntityPlayerMP object. */ /** Reference to the EntityPlayerMP object. */
private EntityPlayerMP playerEntity; private EntityPlayerMP playerEntity;
@@ -374,8 +377,11 @@ @@ -374,8 +378,11 @@
double var10 = this.playerEntity.posY - ((double)var6 + 0.5D) + 1.5D; double var10 = this.playerEntity.posY - ((double)var6 + 0.5D) + 1.5D;
double var12 = this.playerEntity.posZ - ((double)var7 + 0.5D); double var12 = this.playerEntity.posZ - ((double)var7 + 0.5D);
double var14 = var8 * var8 + var10 * var10 + var12 * var12; double var14 = var8 * var8 + var10 * var10 + var12 * var12;
@ -32,7 +37,7 @@
{ {
return; return;
} }
@@ -397,7 +403,7 @@ @@ -397,7 +404,7 @@
if (par1Packet14BlockDig.status == 0) if (par1Packet14BlockDig.status == 0)
{ {
@ -41,7 +46,7 @@
{ {
this.playerEntity.playerNetServerHandler.sendPacket(new Packet53BlockChange(var5, var6, var7, var2)); this.playerEntity.playerNetServerHandler.sendPacket(new Packet53BlockChange(var5, var6, var7, var2));
} }
@@ -467,8 +473,9 @@ @@ -467,8 +474,9 @@
{ {
var12 = var11; var12 = var11;
} }
@ -53,7 +58,7 @@
{ {
this.playerEntity.itemInWorldManager.activeBlockOrUseItem(this.playerEntity, var2, var3, var5, var6, var7, var8); this.playerEntity.itemInWorldManager.activeBlockOrUseItem(this.playerEntity, var2, var3, var5, var6, var7, var8);
} }
@@ -602,9 +609,13 @@ @@ -602,9 +610,13 @@
} }
else else
{ {
@ -70,7 +75,7 @@
} }
this.field_45001_m += 20; this.field_45001_m += 20;
@@ -648,6 +659,10 @@ @@ -648,6 +660,10 @@
} }
} }
} }
@ -81,7 +86,7 @@
else else
{ {
String var3; String var3;
@@ -765,9 +780,10 @@ @@ -765,9 +781,10 @@
*/ */
public void handleRespawn(Packet9Respawn par1Packet9Respawn) public void handleRespawn(Packet9Respawn par1Packet9Respawn)
{ {
@ -93,7 +98,7 @@
} }
else else
{ {
@@ -776,7 +792,7 @@ @@ -776,7 +793,7 @@
return; return;
} }
@ -102,20 +107,17 @@
} }
} }
@@ -969,9 +985,56 @@ @@ -969,9 +986,78 @@
{ {
this.playerEntity.capabilities.isFlying = par1Packet202PlayerAbilities.isFlying && this.playerEntity.capabilities.allowFlying; this.playerEntity.capabilities.isFlying = par1Packet202PlayerAbilities.isFlying && this.playerEntity.capabilities.allowFlying;
} }
-
+ +
+ public EntityPlayerMP getPlayerEntity() + public EntityPlayerMP getPlayerEntity()
+ { + {
+ return playerEntity; + return playerEntity;
+ } + }
+ +
@Override + @Override
- public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
- FMLServerHandler.instance().handlePacket250(par1Packet250CustomPayload, playerEntity);
+ public void handleCustomPayload(Packet250CustomPayload pkt) + public void handleCustomPayload(Packet250CustomPayload pkt)
+ { + {
+ FMLServerHandler.instance().handlePacket250(pkt, playerEntity); + FMLServerHandler.instance().handlePacket250(pkt, playerEntity);
@ -160,5 +162,29 @@
+ public void handleMapData(Packet131MapData par1Packet131MapData) + public void handleMapData(Packet131MapData par1Packet131MapData)
+ { + {
+ ForgeHooks.onItemDataPacket(netManager, par1Packet131MapData); + ForgeHooks.onItemDataPacket(netManager, par1Packet131MapData);
+ }
@Override
- public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
- FMLServerHandler.instance().handlePacket250(par1Packet250CustomPayload, playerEntity);
+ public void handleTileEntityData(Packet132TileEntityData pkt)
+ {
+ World world = this.getPlayerEntity().worldObj;
+ if (world.blockExists(pkt.xPosition, pkt.yPosition, pkt.zPosition))
+ {
+ TileEntity te = world.getBlockTileEntity(pkt.xPosition, pkt.yPosition, pkt.zPosition);
+ if (te != null)
+ {
+ te.onDataPacket(netManager, pkt);
+ }
+ else
+ {
+ ModLoader.getLogger().log(Level.WARNING, String.format(
+ "Received a TileEntityData packet for a location that did not have a TileEntity: (%d, %d, %d) %d: %d, %d, %d",
+ pkt.xPosition, pkt.yPosition, pkt.zPosition,
+ pkt.actionType,
+ pkt.customParam1, pkt.customParam2, pkt.customParam3));
+ }
+ }
} }
} }

View file

@ -1,6 +1,6 @@
--- ../src_base/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000
@@ -204,4 +204,13 @@ @@ -204,4 +204,24 @@
public static void addNewTileEntityMapping(Class<? extends TileEntity> tileEntityClass, String id) { public static void addNewTileEntityMapping(Class<? extends TileEntity> tileEntityClass, String id) {
addMapping(tileEntityClass, id); addMapping(tileEntityClass, id);
} }
@ -13,4 +13,15 @@
+ { + {
+ return true; + return true;
+ } + }
+
+ /**
+ * Called when you receive a TileEntityData packet for the location this
+ * TileEntity is currently in. On the client, the NetworkManager will always
+ * be the remote server. On the server, it will be whomever is responsible for
+ * sending the packet.
+ *
+ * @param net The NetworkManager the packet originated from
+ * @param pkt The data packet
+ */
+ public void onDataPacket(NetworkManager net, Packet132TileEntityData pkt){}
} }