mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-14 01:04:24 +00:00
Add in a simple packet dispatcher for sending packets around
This commit is contained in:
1 parent
b39afc0711
commit
ef5349dec2
4 files changed
+54
No files matched your search
@@ -392,4 +392,10 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
{
|
||||
return client.func_71401_C();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet packet)
|
||||
{
|
||||
client.field_71439_g.field_71174_a.func_72546_b(packet);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.src.DedicatedServer;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
import cpw.mods.fml.common.modloader.ModProperty;
|
||||
@@ -35,4 +36,6 @@ public interface IFMLSidedHandler
|
||||
void finishServerLoading();
|
||||
|
||||
MinecraftServer getServer();
|
||||
|
||||
void sendPacket(Packet packet);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cpw.mods.fml.common.network;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.src.EntityPlayerMP;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
/**
|
||||
* A simple utility class to send packet 250 packets around the place
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class PacketDispatcher
|
||||
{
|
||||
public static Packet250CustomPayload getPacket(String type, byte[] data)
|
||||
{
|
||||
return new Packet250CustomPayload(type, data);
|
||||
}
|
||||
|
||||
public static void sendPacketToServer(Packet packet)
|
||||
{
|
||||
FMLCommonHandler.instance().getSidedDelegate().sendPacket(packet);
|
||||
}
|
||||
|
||||
public static void sendPacketToPlayer(Packet packet, Player player)
|
||||
{
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP)player).field_71135_a.func_72567_b(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacketToAllAround(double X, double Y, double Z, double range, int dimensionId, Packet packet)
|
||||
{
|
||||
FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().func_72393_a(X, Y, Z, range, dimensionId, packet);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.MLProp;
|
||||
import net.minecraft.src.NetworkManager;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.Packet1Login;
|
||||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.Packet3Chat;
|
||||
@@ -174,4 +175,9 @@ public class FMLServerHandler implements IFMLSidedHandler
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
@Override
|
||||
public void sendPacket(Packet packet)
|
||||
{
|
||||
throw new RuntimeException("You cannot send a bare packet without a target on the server!");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user