Jump to content

Recommended Posts

Posted (edited)

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
  • 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.