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


Java INetHandler類代碼示例

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


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

示例1: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的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: processPacket

import net.minecraft.network.INetHandler; //導入依賴的package包/類
/**
 * Passes this Packet on to the NetHandler for processing.
 */
@Override
public void processPacket(INetHandler inethandler)
{
    this.netHandler = inethandler;
    EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target);
    if (internalChannel != null)
    {
        internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler);
        try
        {
            if (internalChannel.writeInbound(this))
            {
                badPackets.add(this.channel);
                if (badPackets.size() % packetCountWarning == 0)
                {
                    FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size());
                    int i = 0;
                    for (Entry<String> s  : Multisets.copyHighestCountFirst(badPackets).entrySet())
                    {
                        if (i++ > 10) break;
                        FMLLog.severe("\t %s : %d", s.getElement(), s.getCount());
                    }
                }
            }
            internalChannel.inboundMessages().clear();
        }
        catch (FMLNetworkException ne)
        {
            FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake(ne.getMessage());
        }
        catch (Throwable t)
        {
            FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake("A fatal error has occurred, this connection is terminated");
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:42,代碼來源:FMLProxyPacket.java

示例3: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, IPacket msg) throws Exception
{
    INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    EntityPlayer player = GalacticraftCore.proxy.getPlayerFromNetHandler(netHandler);

    switch (FMLCommonHandler.instance().getEffectiveSide())
    {
    case CLIENT:
        msg.handleClientSide(player);
        break;
    case SERVER:
        msg.handleServerSide(player);
        break;
    default:
        break;
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:19,代碼來源:GalacticraftPacketHandler.java

示例4: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, IPacket msg) throws Exception {
	INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
	EntityPlayer player = VivecraftForge.proxy.getPlayerFromNetHandler(netHandler);

	switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case CLIENT:
			msg.handleClient(player);
			break;
		case SERVER:
			msg.handleServer(player);
			break;
		default:
			VivecraftForgeLog.severe("Impossible scenario encountered! Effective side is neither server nor client!");
			break;
	}
}
 
開發者ID:Techjar,項目名稱:VivecraftForgeExtensions,代碼行數:18,代碼來源:VivecraftForgePacketHandler.java

示例5: onPacketData

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@SuppressWarnings( "unchecked" )
public void onPacketData(
		final FMLProxyPacket packet,
		final INetHandler handler,
		final EntityPlayerMP playerEntity )
{
	if ( playerEntity == null )
	{
		return;
	}

	final PacketBuffer buffer = new PacketBuffer( packet.payload() );
	final ModPacket innerPacket = parsePacket( buffer );
	innerPacket.serverEntity = playerEntity;

	PacketThreadUtil.checkThreadAndEnqueue( innerPacket, handler, playerEntity.getServer() );
	innerPacket.server( playerEntity );
}
 
開發者ID:AlgorithmX2,項目名稱:Ambidextrous,代碼行數:19,代碼來源:NetworkRouter.java

示例6: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
	INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

	switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case CLIENT:
			packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer());
			break;
		case SERVER:
			packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
			break;
		default:
			break;
	}

}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:17,代碼來源:MCPacketHandler.java

示例7: monitorIncoming

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
public void monitorIncoming( INetHandler net, net.minecraft.network.Packet packet )
{
	if ( !( net instanceof NetHandlerPlayServer ) || !( packet instanceof C0BPacketEntityAction ) )
	{
		return;
	}
	
	NetHandlerPlayServer server = ( NetHandlerPlayServer ) net;
	C0BPacketEntityAction action = ( C0BPacketEntityAction ) packet;
	
	if ( action.func_149513_d() != 6 || !( server.playerEntity.ridingEntity instanceof PetEntity ) )
	{
		return;
	}
	PetEntity pet = ( PetEntity ) server.playerEntity.ridingEntity;

	pet.setJumpingState( action.func_149512_e() );
}
 
開發者ID:spacechase0,項目名稱:UsefulPets,代碼行數:20,代碼來源:JumpPacketMonitor.java

示例8: processPacket

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Redirect(method = "channelRead0", at = @At(value = "INVOKE", target = "net/minecraft/network/Packet.processPacket(Lnet/minecraft/network/INetHandler;)V"))
@SuppressWarnings("unchecked")
private void processPacket(Packet<?> packetIn, INetHandler handler) {
    PacketEvent event = new PacketEvent.Receive(packetIn);
    ClientAPI.EVENT_BUS.post(event);
    if (event.isCancelled())
        return;

    ((Packet<INetHandler>) event.getPacket()).processPacket(handler);
}
 
開發者ID:ImpactDevelopment,項目名稱:ClientAPI,代碼行數:11,代碼來源:MixinNetworkManager.java

示例9: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的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

示例10: getWorldThread

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
public IThreadListener getWorldThread(INetHandler net)
{
    if (net instanceof INetHandlerPlayClient ||
        net instanceof INetHandlerLoginClient ||
        net instanceof INetHandlerStatusClient) return getClient();
    if (net instanceof INetHandlerHandshakeServer ||
        net instanceof INetHandlerLoginServer ||
        net instanceof INetHandlerPlayServer ||
        net instanceof INetHandlerStatusServer) return getServer();
    throw new RuntimeException("Unknown INetHandler: " + net);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:13,代碼來源:FMLClientHandler.java

示例11: channelRead0

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, REQ msg) throws Exception
{
    INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    MessageContext context = new MessageContext(iNetHandler, side);
    REPLY result = messageHandler.onMessage(msg, context);
    if (result != null)
    {
        ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);
        ctx.writeAndFlush(result).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:13,代碼來源:SimpleChannelHandlerWrapper.java

示例12: getPlayerFromNetHandler

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
public EntityPlayer getPlayerFromNetHandler(final INetHandler handler) {
    final EntityPlayer player = super.getPlayerFromNetHandler(handler);
    if (player == null) {
        return this.getClientPlayer();
    }
    return player;
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:9,代碼來源:ExtraUtilsClient.java

示例13: processPacket

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@SideOnly(Side.CLIENT)
@Override
public void processPacket(INetHandler var1)
{
    if (this.type != EnumSimplePacket.C_UPDATE_SPACESTATION_LIST && this.type != EnumSimplePacket.C_UPDATE_PLANETS_LIST && this.type != EnumSimplePacket.C_UPDATE_CONFIGS)
    {
        return;
    }

    if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
    {
        this.handleClientSide(FMLClientHandler.instance().getClientPlayerEntity());
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:15,代碼來源:PacketSimple.java

示例14: getPlayerFromNetHandler

import net.minecraft.network.INetHandler; //導入依賴的package包/類
public EntityPlayer getPlayerFromNetHandler(INetHandler handler)
{
    if (handler instanceof NetHandlerPlayServer)
    {
        return ((NetHandlerPlayServer) handler).playerEntity;
    }
    else
    {
        return null;
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:12,代碼來源:CommonProxyCore.java

示例15: getPlayerFromNetHandler

import net.minecraft.network.INetHandler; //導入依賴的package包/類
@Override
public EntityPlayer getPlayerFromNetHandler(INetHandler handler)
{
    if (handler instanceof NetHandlerPlayServer)
    {
        return ((NetHandlerPlayServer) handler).playerEntity;
    }
    else
    {
        return FMLClientHandler.instance().getClientPlayerEntity();
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:13,代碼來源:ClientProxyCore.java


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