Capture and leverage Packet131MapData

This commit is contained in:
Christian 2012-09-06 10:03:30 -04:00
parent 50c74f93bd
commit 8b8d9a58f6
13 changed files with 185 additions and 7 deletions

View file

@ -27,7 +27,10 @@ import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving; import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiScreen; import net.minecraft.src.GuiScreen;
import net.minecraft.src.NetClientHandler;
import net.minecraft.src.NetHandler;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.Packet131MapData;
import net.minecraft.src.Render; import net.minecraft.src.Render;
import net.minecraft.src.RenderManager; import net.minecraft.src.RenderManager;
import net.minecraft.src.World; import net.minecraft.src.World;
@ -400,4 +403,10 @@ public class FMLClientHandler implements IFMLSidedHandler
{ {
return loading; return loading;
} }
@Override
public void handleTinyPacket(NetHandler handler, Packet131MapData mapData)
{
((NetClientHandler)handler).fmlPacket131Callback(mapData);
}
} }

View file

@ -25,6 +25,8 @@ import net.minecraft.src.DedicatedServer;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP; import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.NetHandler;
import net.minecraft.src.Packet131MapData;
import net.minecraft.src.ServerListenThread; import net.minecraft.src.ServerListenThread;
import net.minecraft.src.ThreadServerApplication; import net.minecraft.src.ThreadServerApplication;
import net.minecraft.src.World; import net.minecraft.src.World;
@ -401,4 +403,9 @@ public class FMLCommonHandler
crashReport.func_71500_a(call.getLabel(), call); crashReport.func_71500_a(call.getLabel(), call);
} }
} }
public void handleTinyPacket(NetHandler handler, Packet131MapData mapData)
{
sidedDelegate.handleTinyPacket(handler, mapData);
}
} }

View file

@ -4,7 +4,9 @@ import java.util.List;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.NetHandler;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.Packet131MapData;
import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket;
import cpw.mods.fml.common.network.EntitySpawnPacket; import cpw.mods.fml.common.network.EntitySpawnPacket;
import cpw.mods.fml.common.network.ModMissingPacket; import cpw.mods.fml.common.network.ModMissingPacket;
@ -33,4 +35,6 @@ public interface IFMLSidedHandler
void sendPacket(Packet packet); void sendPacket(Packet packet);
void displayMissingMods(ModMissingPacket modMissingPacket); void displayMissingMods(ModMissingPacket modMissingPacket);
void handleTinyPacket(NetHandler handler, Packet131MapData mapData);
} }

View file

@ -16,11 +16,13 @@ import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP; import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.EnumGameType; import net.minecraft.src.EnumGameType;
import net.minecraft.src.Item;
import net.minecraft.src.NetHandler; import net.minecraft.src.NetHandler;
import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetLoginHandler;
import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetServerHandler;
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.Packet1Login; import net.minecraft.src.Packet1Login;
import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.Packet3Chat; import net.minecraft.src.Packet3Chat;
@ -396,4 +398,16 @@ public class FMLNetworkHandler
{ {
return NetworkRegistry.instance().handleChat(handler, chat); return NetworkRegistry.instance().handleChat(handler, chat);
} }
public static void handlePacket131Packet(NetHandler handler, Packet131MapData mapData)
{
if (handler instanceof NetServerHandler || mapData.field_73438_a != Item.field_77744_bd.field_77779_bT)
{
NetworkRegistry.instance().handleTinyPacket(handler, mapData);
}
else
{
FMLCommonHandler.instance().handleTinyPacket(handler, mapData);
}
}
} }

View file

@ -0,0 +1,9 @@
package cpw.mods.fml.common.network;
import net.minecraft.src.NetHandler;
import net.minecraft.src.Packet131MapData;
public interface ITinyPacketHandler
{
void handle(NetHandler handler, Packet131MapData mapData);
}

View file

@ -5,6 +5,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import net.minecraft.src.Packet131MapData;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface NetworkMod public @interface NetworkMod
@ -42,6 +44,13 @@ public @interface NetworkMod
*/ */
Class<? extends IPacketHandler> packetHandler() default NULL.class; Class<? extends IPacketHandler> packetHandler() default NULL.class;
/**
* A tiny packet handler implementation based on {@link Packet131MapData} for "small"
* data packet loads.
*
* @return
*/
Class<? extends ITinyPacketHandler> tinyPacketHandler() default NULL.class;
/** /**
* A connection handler implementation for this network mod * A connection handler implementation for this network mod
* *
@ -66,7 +75,7 @@ public @interface NetworkMod
* @author cpw * @author cpw
* *
*/ */
static interface NULL extends IPacketHandler, IConnectionHandler {}; static interface NULL extends IPacketHandler, IConnectionHandler, ITinyPacketHandler {};
/** /**
* A marker for a method that will be offered the client's version string * A marker for a method that will be offered the client's version string
@ -89,4 +98,5 @@ public @interface NetworkMod
String[] channels(); String[] channels();
Class<? extends IPacketHandler> packetHandler(); Class<? extends IPacketHandler> packetHandler();
} }
} }

View file

@ -4,6 +4,8 @@ import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import net.minecraft.src.Item;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -22,6 +24,7 @@ public class NetworkModHandler
private static Object packetHandlerDefaultValue; private static Object packetHandlerDefaultValue;
private static Object clientHandlerDefaultValue; private static Object clientHandlerDefaultValue;
private static Object serverHandlerDefaultValue; private static Object serverHandlerDefaultValue;
private static Object tinyPacketHandlerDefaultValue;
private static int assignedIds = 1; private static int assignedIds = 1;
@ -33,6 +36,7 @@ public class NetworkModHandler
private Method checkHandler; private Method checkHandler;
private VersionRange acceptableRange; private VersionRange acceptableRange;
private ITinyPacketHandler tinyPacketHandler;
public NetworkModHandler(ModContainer container, NetworkMod modAnnotation) public NetworkModHandler(ModContainer container, NetworkMod modAnnotation)
{ {
@ -40,6 +44,11 @@ public class NetworkModHandler
this.mod = modAnnotation; this.mod = modAnnotation;
this.localId = assignedIds++; this.localId = assignedIds++;
this.networkId = this.localId; this.networkId = this.localId;
// Skip over the map object because it has special network id meaning
if (Item.field_77744_bd.field_77779_bT == assignedIds)
{
assignedIds++;
}
} }
public NetworkModHandler(ModContainer container, Class<?> networkModClass, ASMDataTable table) public NetworkModHandler(ModContainer container, Class<?> networkModClass, ASMDataTable table)
{ {
@ -130,6 +139,19 @@ public class NetworkModHandler
NetworkRegistry.instance().registerConnectionHandler(instance); NetworkRegistry.instance().registerConnectionHandler(instance);
} }
if (mod.tinyPacketHandler()!=tinyPacketHandlerDefaultValue)
{
try
{
tinyPacketHandler = mod.tinyPacketHandler().newInstance();
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "Unable to create tiny packet handler instance %s", mod.tinyPacketHandler().getName());
throw new FMLNetworkException(e);
}
}
} }
/** /**
* @param container * @param container
@ -206,6 +228,20 @@ public class NetworkModHandler
} }
} }
private Object getTinyPacketHandlerDefaultValue()
{
try {
if (tinyPacketHandlerDefaultValue == null)
{
tinyPacketHandlerDefaultValue = NetworkMod.class.getMethod("tinyPacketHandler").getDefaultValue();
}
return tinyPacketHandlerDefaultValue;
}
catch (NoSuchMethodException e)
{
throw new RuntimeException("Derp?", e);
}
}
/** /**
* @return * @return
*/ */
@ -302,4 +338,13 @@ public class NetworkModHandler
{ {
this.networkId = value; this.networkId = value;
} }
public boolean hasTinyPacketHandler()
{
return tinyPacketHandler != null;
}
public ITinyPacketHandler getTinyPacketHandler()
{
return tinyPacketHandler;
}
} }

View file

@ -14,6 +14,7 @@ import net.minecraft.src.NetHandler;
import net.minecraft.src.NetLoginHandler; import net.minecraft.src.NetLoginHandler;
import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetServerHandler;
import net.minecraft.src.NetworkManager; import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet131MapData;
import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet1Login;
import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.Packet3Chat; import net.minecraft.src.Packet3Chat;
@ -337,4 +338,21 @@ public class NetworkRegistry
return chat; return chat;
} }
public void handleTinyPacket(NetHandler handler, Packet131MapData mapData)
{
NetworkModHandler nmh = FMLNetworkHandler.instance().findNetworkModHandler(mapData.field_73438_a);
if (nmh == null)
{
FMLLog.info("Received a tiny packet for network id %d that is not recognised here", mapData.field_73438_a);
return;
}
if (nmh.hasTinyPacketHandler())
{
nmh.getTinyPacketHandler().handle(handler, mapData);
}
else
{
FMLLog.info("Received a tiny packet for a network mod that does not accept tiny packets %s", nmh.getContainer().getModId());
}
}
} }

View file

@ -45,4 +45,30 @@ public class PacketDispatcher
FMLLog.fine("Attempt to send packet to all around without a server instance available"); FMLLog.fine("Attempt to send packet to all around without a server instance available");
} }
} }
public static void sendPacketToAllInDimension(Packet packet, int dimId)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server != null)
{
server.func_71203_ab().func_72396_a(packet, dimId);
}
else
{
FMLLog.fine("Attempt to send packet to all in dimension without a server instance available");
}
}
public static void sendPacketToAllPlayers(Packet packet)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server != null)
{
server.func_71203_ab().func_72384_a(packet);
}
else
{
FMLLog.fine("Attempt to send packet to all in dimension without a server instance available");
}
}
} }

View file

@ -16,7 +16,9 @@ import java.util.List;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.NetHandler;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.Packet131MapData;
import net.minecraft.src.World; import net.minecraft.src.World;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.IFMLSidedHandler;
@ -156,4 +158,9 @@ public class FMLServerHandler implements IFMLSidedHandler
{ {
// NOOP on server // NOOP on server
} }
@Override
public void handleTinyPacket(NetHandler handler, Packet131MapData mapData)
{
// NOOP on server
}
} }

View file

@ -29,11 +29,17 @@
DataInputStream var2; DataInputStream var2;
ItemStack var3; ItemStack var3;
ItemStack var4; ItemStack var4;
@@ -1029,4 +1037,11 @@ @@ -1029,4 +1037,17 @@
} }
} }
} }
+ +
+ @Override
+ public void func_72494_a(Packet131MapData p_72494_1_)
+ {
+ FMLNetworkHandler.handlePacket131Packet(this, p_72494_1_);
+ }
+
+ // modloader compat -- yuk! + // modloader compat -- yuk!
+ @Override + @Override
+ public EntityPlayerMP getPlayer() + public EntityPlayerMP getPlayer()

View file

@ -0,0 +1,11 @@
--- ../src-base/common/net/minecraft/src/Packet.java
+++ ../src-work/common/net/minecraft/src/Packet.java
@@ -341,7 +341,7 @@
func_73285_a(107, true, true, Packet107CreativeSetSlot.class);
func_73285_a(108, false, true, Packet108EnchantItem.class);
func_73285_a(130, true, true, Packet130UpdateSign.class);
- func_73285_a(131, true, false, Packet131MapData.class);
+ func_73285_a(131, true, true, Packet131MapData.class);
func_73285_a(132, true, false, Packet132TileEntityData.class);
func_73285_a(200, true, false, Packet200Statistic.class);
func_73285_a(201, true, false, Packet201PlayerInfo.class);

View file

@ -49,19 +49,31 @@
this.field_72563_h.field_71456_v.func_73827_b().func_73765_a(p_72481_1_.field_73476_b); this.field_72563_h.field_71456_v.func_73827_b().func_73765_a(p_72481_1_.field_73476_b);
} }
@@ -1167,6 +1174,11 @@ @@ -1066,6 +1073,11 @@
public void func_72494_a(Packet131MapData p_72494_1_)
{
+ FMLNetworkHandler.handlePacket131Packet(this, p_72494_1_);
+ }
+
+ public void fmlPacket131Callback(Packet131MapData p_72494_1_)
+ {
if (p_72494_1_.field_73438_a == Item.field_77744_bd.field_77779_bT)
{
ItemMap.func_77874_a(p_72494_1_.field_73436_b, this.field_72563_h.field_71441_e).func_76192_a(p_72494_1_.field_73437_c);
@@ -1166,6 +1178,11 @@
}
public void func_72501_a(Packet250CustomPayload p_72501_1_) public void func_72501_a(Packet250CustomPayload p_72501_1_)
{ + {
+ FMLNetworkHandler.handlePacket250Packet(p_72501_1_, field_72555_g, this); + FMLNetworkHandler.handlePacket250Packet(p_72501_1_, field_72555_g, this);
+ } + }
+ +
+ public void handleVanilla250Packet(Packet250CustomPayload p_72501_1_) + public void handleVanilla250Packet(Packet250CustomPayload p_72501_1_)
+ { {
if ("MC|TPack".equals(p_72501_1_.field_73630_a)) if ("MC|TPack".equals(p_72501_1_.field_73630_a))
{ {
String[] var2 = (new String(p_72501_1_.field_73629_c)).split("\u0000"); @@ -1211,4 +1228,10 @@
@@ -1211,4 +1223,10 @@
{ {
return this.field_72555_g; return this.field_72555_g;
} }