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 c26cbacff..18aa70bf4 100644 --- a/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java +++ b/forge/forge_client/src/net/minecraft/src/forge/PacketHandlerClient.java @@ -14,10 +14,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.src.*; import net.minecraft.src.forge.packets.*; -public class PacketHandlerClient implements IPacketHandler +public class PacketHandlerClient extends PacketHandlerBase { - private static boolean DEBUG = false; - @Override public void onPacketData(NetworkManager network, String channel, byte[] bytes) { @@ -237,4 +235,11 @@ public class PacketHandlerClient implements IPacketHandler player.craftingInventory.windowId = pkt.WindowID; } } + + @Override + public void sendPacket(NetworkManager network, Packet packet) + { + NetClientHandler net = (NetClientHandler)network.getNetHandler(); + net.addToSendQueue(packet); + } } diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index c0790346d..f47147996 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -25,6 +25,7 @@ import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.World; import net.minecraft.src.forge.packets.PacketEntitySpawn; +import net.minecraft.src.forge.packets.PacketHandlerBase; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -645,8 +646,8 @@ public class ForgeHooks static HashMap toolHarvestLevels = new HashMap(); static HashSet toolEffectiveness = new HashSet(); - private static IPacketHandler forgePacketHandler = null; - public static void setPacketHandler(IPacketHandler handler) + private static PacketHandlerBase forgePacketHandler = null; + public static void setPacketHandler(PacketHandlerBase handler) { if (forgePacketHandler != null) { @@ -654,7 +655,7 @@ public class ForgeHooks } forgePacketHandler = handler; } - public static IPacketHandler getPacketHandler() + public static PacketHandlerBase getPacketHandler() { return forgePacketHandler; } diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index 13e70b54b..f6d15aebf 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -13,6 +13,8 @@ import net.minecraft.src.EntityMinecart; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.ModLoader; +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet; import net.minecraft.src.World; import java.util.*; @@ -1121,6 +1123,17 @@ public class MinecraftForge ForgeHooks.arrowLooseHandlers.add(handler); } + /** + * Sends a packet on the specified NetworkManager + * + * @param net The manager to send the packet on + * @param packet The packet to be sent + */ + public static void sendPacket(NetworkManager net, Packet packet) + { + ForgeHooks.getPacketHandler().sendPacket(net, packet); + } + private static int isClient = -1; public static boolean isClient() { diff --git a/forge/forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java b/forge/forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java new file mode 100644 index 000000000..7bbd5d07c --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/packets/PacketHandlerBase.java @@ -0,0 +1,24 @@ +package net.minecraft.src.forge.packets; + +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet; +import net.minecraft.src.forge.IPacketHandler; + +/** + * A helper class used to make a shared interface for sending packets, + * Should not be used outside the API itself. + */ +public abstract class PacketHandlerBase implements IPacketHandler +{ + public static boolean DEBUG = false; + + /** + * Sends out a packet to the specified network manager. + * This is necessary because NetClientHandler, and + * NetServerHandler are not on both sides. + * + * @param network The manager to send the packet to + * @param packet The packet to send + */ + public abstract void sendPacket(NetworkManager network, Packet packet); +} diff --git a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java index 6410fa82e..ad6abc2b3 100644 --- a/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java +++ b/forge/forge_server/src/net/minecraft/src/forge/PacketHandlerServer.java @@ -16,9 +16,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.src.*; import net.minecraft.src.forge.packets.*; -public class PacketHandlerServer implements IPacketHandler +public class PacketHandlerServer extends PacketHandlerBase { - public static boolean DEBUG = false; @Override public void onPacketData(NetworkManager network, String channel, byte[] bytes) { @@ -162,4 +161,11 @@ public class PacketHandlerServer implements IPacketHandler player.func_20057_k(); FMLServerHandler.instance().announceLogin(player); } + + @Override + public void sendPacket(NetworkManager network, Packet packet) + { + NetServerHandler net = (NetServerHandler)network.getNetHandler(); + net.sendPacket(packet); + } }