Java Code Examples for cpw.mods.fml.common.network.simpleimpl.IMessageHandler

The following are top voted examples for showing how to use cpw.mods.fml.common.network.simpleimpl.IMessageHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RorysMod   File: PacketDispatcher.java   View source code 5 votes vote down vote up
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
	if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
	} else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
	} else {
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
	}
}
 
Example 2
Project: LambdaLib   File: MessageHandlerRegistration.java   View source code 5 votes vote down vote up
private <REQ extends IMessage> void register(Class<?> handler, Class<REQ> msg, Side side) {
    Class<? extends IMessageHandler<REQ, IMessage>> messageHandler = (Class<? extends IMessageHandler<REQ, IMessage>>) handler;
    SimpleNetworkWrapper wrapper = (SimpleNetworkWrapper) helper.getModField();
    int id = helper.getNextIDForMod();
    //System.out.println(msg + " -> " + id);
    wrapper.registerMessage(messageHandler, msg, id, side);
}
 
Example 3
Project: RecycleCraft   File: PacketHandler.java   View source code 5 votes vote down vote up
public static void registerPacket(CustomPacket packet) {
	if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
		wrapper.registerMessage((Class<? extends IMessageHandler<CustomPacket, IMessage>>) packet.getClass(), (Class<CustomPacket>) packet.getClass(), counter++, Side.CLIENT);
	}
	else {
		wrapper.registerMessage((Class<? extends IMessageHandler<CustomPacket, IMessage>>) packet.getClass(), (Class<CustomPacket>) packet.getClass(), counter++, Side.SERVER);
	}
}
 
Example 4
Project: EnergizedPower   File: PacketHandler.java   View source code 5 votes vote down vote up
/**
 * Register a packet
 * @param packet the packet to register
 * @param side the side to register the packet for
 * @param id the id of the packet
 */
@SuppressWarnings("unchecked")
public static void register(Class<? extends IPacket> packet, Side side, int id)
{
	Class<? extends Object> clazz = packet;
	INSTANCE.registerMessage((Class<? extends IMessageHandler<IMessage, IMessage>>)clazz, (Class<IMessage>)clazz, id, side);
}
 
Example 5
Project: AutomationMod   File: PacketHandler.java   View source code 5 votes vote down vote up
/**
 * This method assumes that the same class is used for both the message and the message handler
 */
@SuppressWarnings("unchecked")
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<?> clazz, PacketSide side) {
    if (side == PacketSide.CLIENT || side == PacketSide.BOTH) CHANNEL.registerMessage((Class<? extends IMessageHandler<REQ, REPLY>>) clazz, (Class<REQ>) clazz, descriminator, Side.CLIENT);
    if (side == PacketSide.SERVER || side == PacketSide.BOTH) CHANNEL.registerMessage((Class<? extends IMessageHandler<REQ, REPLY>>) clazz, (Class<REQ>) clazz, descriminator, Side.SERVER);
    descriminator++;
}
 
Example 6
Project: projectzulu1.7.10-pre-1.3a   File: PacketPipeline.java   View source code 5 votes vote down vote up
private <REQ extends IMessage, REPLY extends IMessage> void registerUniversalMessage( 
		Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType) {
	network.registerMessage(messageHandler, requestMessageType, discriminator, Side.CLIENT);
	discriminator++;
	network.registerMessage(messageHandler, requestMessageType, discriminator, Side.SERVER);
	discriminator++;
}
 
Example 7
Project: Zombie-Total-Conversion-Craft   File: CommonProxy.java   View source code 5 votes vote down vote up
private void regMessage(Class<? extends IMessage> message, Side side, Side otherSide) {
    if(otherSide != null) {
        regMessage(message, otherSide);
    }
    if(messageID > 255) {
        System.out.println("Warning: Over 255 messages registered, need another channel");
    } else {
        Class<? extends IMessageHandler<IMessage, IMessage>> messageHandlerClass = (Class<? extends IMessageHandler<IMessage, IMessage>>) message.getDeclaredClasses()[0];
        ZombieTC.network.registerMessage(messageHandlerClass, (Class<IMessage>)message, messageID, side);
        messageID++;
    }
}
 
Example 8
Project: Ye-Olde-Chat   File: PacketHandler.java   View source code 4 votes vote down vote up
public static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side receivingSide)
{
    INSTANCE.registerMessage(messageHandler, requestMessageType, counter, receivingSide);
    counter++;
}
 
Example 9
Project: copycore   File: NetworkChannel.java   View source code 4 votes vote down vote up
/** Register a message type with this message handler on this side using the ID. */
public <T extends IMessage & IMessageHandler<T, IMessage>> void register(int id, Side receivingSide, Class<T> messageClass) {
	registerMessage(messageClass, messageClass, id, receivingSide);
}
 
Example 10
Project: projectzulu1.7.10-pre-1.3a   File: PacketPipeline.java   View source code 4 votes vote down vote up
private <REQ extends IMessage, REPLY extends IMessage> void registerClientMessage( 
		Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType) {
	network.registerMessage(messageHandler, requestMessageType, discriminator, Side.CLIENT);
	discriminator++;
}
 
Example 11
Project: projectzulu1.7.10-pre-1.3a   File: PacketPipeline.java   View source code 4 votes vote down vote up
private <REQ extends IMessage, REPLY extends IMessage> void registerServerMessage( 
		Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType) {
	network.registerMessage(messageHandler, requestMessageType, discriminator, Side.SERVER);
	discriminator++;
}
 
Example 12
Project: Yamcl   File: PacketDispatcher.java   View source code 2 votes vote down vote up
/**
 * Register a message; Automatic side detection
 * 
 * @param handlerClass
 * @param messageClass
 */
protected final <REQ extends IMessage, REPLY extends IMessage> void registerMessage( Class<? extends IMessageHandler<REQ, REPLY>> handlerClass, Class<REQ> messageClass )
{
  Side side = AbstractClientMessageHandler.class.isAssignableFrom( handlerClass ) ? Side.CLIENT : Side.SERVER;
  dispatcher.registerMessage( handlerClass, messageClass, _mPacketId++, side );
}
 
Example 13
Project: Dimensional-Pockets   File: NetworkDispatcher.java   View source code 2 votes vote down vote up
/**
 * @param clazz  Class with all the message goodness, must extend MessageAbstract.
 * @param target Side that the message is being sent to.
 */
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends MessageAbstract<REQ, REPLY>> clazz, Side target) {
    network.registerMessage((Class<? extends IMessageHandler<REQ, REPLY>>) clazz, (Class<REQ>) clazz, discriminator++, target);
}
 
Example 14
Project: OmnisCore   File: NetworkDispatcher.java   View source code 2 votes vote down vote up
/**
 * @param clazz  Class with all the message goodness, must extend MessageAbstract.
 * @param target Side that the message is being sent to.
 */
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends MessageAbstract<REQ, REPLY>> clazz, Side target) {
    network.registerMessage((Class<? extends IMessageHandler<REQ, REPLY>>) clazz, (Class<REQ>) clazz, discriminator++, target);
}