ClientMessageHandler:
public abstract class ClientMessageHandler<T extends IMessage> extends AIMessageHandler<T>{
public final IMessage handleServerMessage(EntityPlayer player, T message, MessageContext ctx) {
return null;
}
}
AIMessageHandler:
public abstract class AIMessageHandler<T extends IMessage> implements IMessageHandler<T, IMessage> {
@SideOnly(Side.CLIENT)
public abstract IMessage handleClientMessage (EntityPlayer player, T message, MessageContext ctx);
public abstract IMessage handleServerMessage (EntityPlayer player, T message, MessageContext ctx);
@Override
public IMessage onMessage (T message, MessageContext ctx){
if (ctx.side.isClient()) {
return handleClientMessage(AppliedIntegrations.proxy.getPlayerEntity(ctx), message, ctx);
} else {
return handleServerMessage(AppliedIntegrations.proxy.getPlayerEntity(ctx), message, ctx);
}
}
}
Sending:
NetworkHandler.sendTo(new PacketProgressBar(this), (EntityPlayerMP) listener.player);
Handler:
public class NetworkHandler {
private static byte packetId = 0;
private static final SimpleNetworkWrapper Handler = NetworkRegistry.INSTANCE.newSimpleChannel(AppliedIntegrations.modid);
/**
* Call this during pre-init or loading and register all of your packets (messages) here
*/
public static final void registerPackets() {
NetworkHandler.registerMessage(PacketProgressBar.Handler.class, PacketProgressBar.class, Side.CLIENT);
NetworkHandler.registerMessage(PacketFilterChange.Handler.class,PacketFilterChange.class,Side.SERVER);
NetworkHandler.registerMessage(PacketBarChange.Handler.class,PacketBarChange.class,Side.CLIENT);
}
/**
* Registers a message and message handler
*/
private static final void registerMessage(Class handlerClass, Class messageClass, Side side) {
NetworkHandler.Handler.registerMessage(handlerClass, messageClass, packetId++, side);
}
// send packet info to player
public static final void sendTo(IMessage message, EntityPlayerMP player) {
NetworkHandler.Handler.sendTo(message, player);
}
public static final void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) {
NetworkHandler.Handler.sendToAllAround(message, point);
}
public static final void sendToAllAround(IMessage message, int dimension, double x, double y, double z,
double range) {
NetworkHandler.sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, x, y, z,
range));
}
public static final void sendToAllAround(IMessage message, EntityPlayer player, double range) {
NetworkHandler.sendToAllAround(message, player.worldObj.provider.dimensionId, player.posX,
player.posY, player.posZ, range);
}
public static final void sendToDimension(IMessage message, int dimensionId) {
NetworkHandler.Handler.sendToDimension(message, dimensionId);
}
public static final void sendToServer(IMessage message) {
NetworkHandler.Handler.sendToServer(message);
}
}