本文整理汇总了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()+" ");
}
示例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");
}
}
}
示例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;
}
}
示例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;
}
}
示例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 );
}
示例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;
}
}
示例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() );
}
示例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);
}
示例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()+" ");
}
示例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);
}
示例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);
}
}
示例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;
}
示例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());
}
}
示例14: getPlayerFromNetHandler
import net.minecraft.network.INetHandler; //导入依赖的package包/类
public EntityPlayer getPlayerFromNetHandler(INetHandler handler)
{
if (handler instanceof NetHandlerPlayServer)
{
return ((NetHandlerPlayServer) handler).playerEntity;
}
else
{
return null;
}
}
示例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();
}
}