當前位置: 首頁>>代碼示例>>Java>>正文


Java IMessageHandler類代碼示例

本文整理匯總了Java中net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler的典型用法代碼示例。如果您正苦於以下問題:Java IMessageHandler類的具體用法?Java IMessageHandler怎麽用?Java IMessageHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IMessageHandler類屬於net.minecraftforge.fml.common.network.simpleimpl包,在下文中一共展示了IMessageHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: channelRead0

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
	ByteBuf buffer = msg.content();
	
	int seq = buffer.readUnsignedShort();
	int msgid = buffer.readByte();
	
	IMessage message = TF2weapons.network.messages[msgid].newInstance();
	//buffer.discardReadBytes();
	message.fromBytes(buffer);
	IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass());
	if(constr == null) {
		constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class);
		constr.setAccessible(true);
	}
	MessageContext context = constr.newInstance(Minecraft.getMinecraft().player.connection, Side.CLIENT); 
	handler.onMessage(message, context);
	System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" ");
	
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:21,代碼來源:UdpChannelHandlerClient.java

示例2: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
	// We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

	// Also, one can see the convenience of using a static counter 'packetId' to keep
	// track of the current index, rather than hard-coding them all, plus it's one less
	// parameter to pass.
	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 {
		// hopefully you didn't forget to extend the right class, or you will get registered on both sides
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
		PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
	}
}
 
開發者ID:Ohrm,項目名稱:Malgra,代碼行數:20,代碼來源:PacketDispatcher.java

示例3: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    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 {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
 
開發者ID:kamildanak,項目名稱:EnderPay,代碼行數:20,代碼來源:PacketDispatcher.java

示例4: registerPacket

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public static <REQ extends IMessage, REPLY extends IMessage> void registerPacket(SimpleNetworkWrapper network, Class<REQ> requestMessageType, Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Side side) {
	String packetPackageName = requestMessageType.getPackage().getName();
	Iterator<String> iterator = packetByteDiscriminators.keySet().iterator();
	
	byte discriminator = -1;
	while(iterator.hasNext()) {
		String pack = iterator.next();
		
		if(pack.contains(packetPackageName)) {
			packetByteDiscriminators.get(packetPackageName);
		}
	}
	
	if(discriminator == -1) {
		packetByteDiscriminators.put(packetPackageName, (byte) 0);
	}
	
	network.registerMessage(messageHandler, requestMessageType, packetByteDiscriminators.get(packetPackageName), side);
}
 
開發者ID:Geforce132,項目名稱:AllPI,代碼行數:20,代碼來源:PacketHelper.java

示例5: getHandlers

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public static HandlersInfo getHandlers(Class message) {
    Class[] handlerCandidates = message.getDeclaredClasses();
    Class clientHandler = null, serverHandler = null;

    for (int x = 0; x < handlerCandidates.length; x++) {
        if (IMessageHandler.class.isAssignableFrom(handlerCandidates[x])) {
            if (ClientHandler.class.isAssignableFrom(handlerCandidates[x])) {
                clientHandler = handlerCandidates[x];
            }

            if (ServerHandler.class.isAssignableFrom(handlerCandidates[x])) {
                serverHandler = handlerCandidates[x];
            }

            if (serverHandler != null && clientHandler != null) break;
        }
    }

    HandlersInfo info = new HandlersInfo();
    info.client = clientHandler;
    info.server = serverHandler;

    return info;
}
 
開發者ID:chedim,項目名稱:minedriod,代碼行數:25,代碼來源:APacket.java

示例6: checkThreadAndEnqueue

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public static <T extends IMessage> boolean checkThreadAndEnqueue(final T message, final IMessageHandler<T, IMessage> handler, final MessageContext ctx, IThreadListener listener)
{
    if (!listener.isCallingFromMinecraftThread())
    {
        listener.addScheduledTask(() -> handler.onMessage(message, ctx));
        return true;
    }

    return false;
}
 
開發者ID:cubex2,項目名稱:customstuff4,代碼行數:11,代碼來源:NetworkHelper.java

示例7: channelRead0

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
	ByteBuf buffer = msg.content();
	
	int plid = buffer.readShort();
	int seq = buffer.readUnsignedShort();
	int msgid = buffer.readByte();
	
	if(msgid == (byte)-128) {
		server.outboundTargets.put((short) plid, SocketUtils.socketAddress(msg.sender().getAddress().getHostAddress(),msg.sender().getPort()));
	}
	else {
		EntityPlayerMP player = server.playerList.get((short)plid);
		IMessage message = TF2weapons.network.messages[msgid].newInstance();
		//buffer.discardReadBytes();
		message.fromBytes(buffer);
		IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass());
		if(constr == null) {
			constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class);
			constr.setAccessible(true);
		}
		MessageContext context = constr.newInstance(player.connection, Side.SERVER); 
		handler.onMessage(message, context);
	}
	System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" ");
	
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:28,代碼來源:UdpChannelHandlerServer.java

示例8: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp)
  {
      try {
	registerMessage(messageHandler.newInstance(), requestMessageType, discriminator, side, useUdp);
} catch (Exception e) {
	
}
  }
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:9,代碼來源:TF2NetworkWrapper.java

示例9: addNetworkPacket

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public <REQ extends IMessage, REPLY extends IMessage> void addNetworkPacket(
		Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType,
		int discriminator, Side side) {
	if (netChannel == null)
		netChannel = NetworkRegistry.INSTANCE.newSimpleChannel(modId);
	netChannel.registerMessage(messageHandler, requestMessageType, discriminator, side);
}
 
開發者ID:hea3ven,項目名稱:CommonUtils,代碼行數:8,代碼來源:ProxyModBase.java

示例10: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
private static <T extends MessageBase<T> & IMessageHandler<T, IMessage>>void registerMessage(Class<T> clazz) {
    if(ClientMessageBase.class.isAssignableFrom(clazz)) {
        CHANNEL.registerMessage(clazz, clazz, ID++, Side.CLIENT);
        return;
    }
    if(ServerMessageBase.class.isAssignableFrom(clazz)) {
        CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER);
        return;
    }
    CHANNEL.registerMessage(clazz, clazz, ID, Side.CLIENT);
    CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER);
}
 
開發者ID:CenturionFox,項目名稱:wolfarmor,代碼行數:13,代碼來源:PacketHandler.java

示例11: cPacket

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
/** Helper for registering server -> client packets. */
private static <REQ extends IMessage, REPLY extends IMessage> void
        cPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler,
        Class<REQ> packet) {
    
    NETWORK.registerMessage(handler, packet, packetID++, Side.CLIENT);
}
 
開發者ID:JayAvery,項目名稱:geomastery,代碼行數:8,代碼來源:Geomastery.java

示例12: sPacket

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
/** Helper for registering client -> server packets. */
private static <REQ extends IMessage, REPLY extends IMessage> void
        sPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler,
        Class<REQ> packet) {
    
    NETWORK.registerMessage(handler, packet, packetID++, Side.SERVER);
}
 
開發者ID:JayAvery,項目名稱:geomastery,代碼行數:8,代碼來源:Geomastery.java

示例13: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
private static <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);
	}
}
 
開發者ID:Wehavecookies56,項目名稱:Bonfires,代碼行數:11,代碼來源:PacketDispatcher.java

示例14: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
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);
    }
}
 
開發者ID:Wehavecookies56,項目名稱:Kingdom-Keys-Re-Coded,代碼行數:11,代碼來源:PacketDispatcher.java

示例15: registerMessage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; //導入依賴的package包/類
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> registee){
    if(AbstractMessage.AbstractClientMessage.class.isAssignableFrom(registee)){
        MessageDispatcher.INSTANCE.registerMessage(registee, registee, packetid++, Side.CLIENT);
    }else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(registee)){
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER);
    }else{
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.CLIENT);
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER);

    }
}
 
開發者ID:Mattpenguin,項目名稱:MagicaSolaris,代碼行數:12,代碼來源:MessageDispatcher.java


注:本文中的net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。