Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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/

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.