当前位置: 首页>>代码示例>>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;未经允许,请勿转载。