Jump to content

[1.7.10] ServerCustomPacketEvent not firing


TheGamerPlayz

Recommended Posts

Hello, I'm new to forge modding (But not to java), but have never really messed with servers and clients. I am using a method of packets that use the ServerCustomPacketEvent however it is not firing. I have a KeyInputEvent being registered in the same way and it is firing just fine.

 

This would be the ServerCustomPackEvent:

Spoiler

	@SubscribeEvent
	public void onPacket(ServerCustomPacketEvent event) {
		String channelName = event.packet.channel();
	    System.out.println("Recieving Packet from channel: " + channelName);
	      
	    NetHandlerPlayServer theNetHandlerPlayServer = (NetHandlerPlayServer) event.handler;
	    EntityPlayer thePlayer = theNetHandlerPlayServer.playerEntity;
	  
	    if(channelName.equals(ModUtils.MODID)) {
	    	try {
		         System.out.println("Server received packet from player = "+thePlayer.getEntityId());
				 ProcessPacketServerSide.processPacketOnServer(event.packet.payload(), event.packet.getTarget(), thePlayer);
			}
	        catch (IOException e) {
			e.printStackTrace();
	        }
	    }
	}

 

 

This is the ProccessPacketServerSide:

Spoiler

	public static void processPacketOnServer(ByteBuf parBB, Side parSide, EntityPlayer parPlayer)
			throws IOException {
		if(parSide == Side.SERVER) {
			System.out.println("Received Packet on Server Side from Player = " + parPlayer.getEntityId());

			ByteBufInputStream bbis = new ByteBufInputStream(parBB);
			   
			int packetTypeID = bbis.readInt();
			System.out.println("Packet type ID = " + packetTypeID);
			  
			if(packetTypeID == ServerPacketHandler.STATGUIPACKETREQEUST) {
				System.out.println("Loading Player Stats...");
			}
			   
			bbis.close();
		}
	}

 

 

This is how I am sending the packet:

Spoiler

	public static FMLProxyPacket createRequestStatsPacket() throws IOException {
		EntityClientPlayerMP parEntity = Minecraft.getMinecraft().thePlayer;

		System.out.println("Creating StatRequestPacket on Client Side");
		ByteBufOutputStream bbos = new ByteBufOutputStream(Unpooled.buffer());
	
		bbos.writeInt(ServerPacketHandler.STATGUIPACKETREQEUST);
		bbos.writeInt(parEntity.getEntityId());
	   
	    FMLProxyPacket thePacket = new FMLProxyPacket(bbos.buffer(), NarutoUtils.MODID);
	    
	    bbos.close();
	    
	    return thePacket;
	}

public static void requestStats() {
	   try {
		   CreatePacketClientSide.sendToServer(CreatePacketClientSide.createRequestStatsPacket());
	   }
	   catch (IOException e) {
		   e.printStackTrace();
	   }
   }
 
   public static void sendToServer(FMLProxyPacket parPacket) {
        MyMod.channel.sendToServer(parPacket);
		System.out.println("Sending packet...");
   }

 

And this is where I am registering the event:

Spoiler

 


	private void init() {
    	NetworkRegistry.INSTANCE.registerGuiHandler(NarutoMod.instance, new GuiHandler());
    	keyhandler = new KeyHandler();
    	FMLCommonHandler.instance().bus().register(keyhandler);
    	FMLCommonHandler.instance().bus().register(new ServerPacketHandler());
    	FMLCommonHandler.instance().bus().register(new ClientPacketHandler());
	}
Spoiler

 

 

Does anyone see any reason it would not be receiving the Packet?

Edited by TheGamerPlayz
Link to comment
Share on other sites

1.7.10 is no longer supported by Forge. This will get locked once a moderator sees this.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.