Added generic packet sending function to MinecraftForge class.
This commit is contained in:
parent
ddd4b6eb48
commit
23ffbb774f
5 changed files with 57 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue