本文整理匯總了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()+" ");
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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()+" ");
}
示例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) {
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}