Get Textfield on server

Started by nathyperfort on Sun, 01/23/2022 - 15:19

Topic category: Help with modding (Java Edition)

Last seen on 20:29, 16. Feb 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Get Textfield on server
Sun, 01/23/2022 - 15:19

Hello,

What i want is Very simple.

Imagine you open a gui with command.

In this gui, there is a textfield and a button

What I want is : When I click on the button, it prints to the player what he wrote into the textfiled.

It works fine on singleplayer world, but not when connected to local server (text always blank)

I looked into the code of mcreator, and I dont know if I'm right but it seems guistate isn't sended at all when on server.

Sow what can i do ? Thanks !

This is not possible right…
Tue, 01/25/2022 - 09:07

This is not possible right now without custom network packet to sync the client contents to the server

Last seen on 20:29, 16. Feb 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thanks for your reply ! So I…
Thu, 01/27/2022 - 11:40

Thanks for your reply !

So I'm trying to make this custom packet. (1.16)

How I work :

I register an event which listens every key typed on keyboard IF my custom gui is open

Then it sends the textfield content to the server which will edit persistent player variables and resync them to client.

I managed to make packet classes and event listener

BUT the game crashes when I type a key (in my gui).

I have no idea why the game says Invalid packet.

Here is the code : Packet Class : https://pastebin.com/W4624LxY

Event Class : https://pastebin.com/E3PYArhP

Error :

java.lang.IllegalArgumentException: Invalid message net.mcreator.modid.TextFieldPacketHandler$TextFieldDataSyncMessage
at net.minecraftforge.fml.network.simple.IndexedMessageCodec.build(IndexedMessageCodec.java:145)
at net.minecraftforge.fml.network.simple.SimpleChannel.encodeMessage(SimpleChannel.java:85)
at net.minecraftforge.fml.network.simple.SimpleChannel.toBuffer(SimpleChannel.java:98)
at net.minecraftforge.fml.network.simple.SimpleChannel.toVanillaPacket(SimpleChannel.java:129)
at net.minecraftforge.fml.network.simple.SimpleChannel.sendTo(SimpleChannel.java:109)
at net.minecraftforge.fml.network.simple.SimpleChannel.sendToServer(SimpleChannel.java:104)
at net.mcreator.modid.OnKeyPressed$ForgeBusEvents.keyPressed(OnJumpKeyPressed.java:61)

Thanks for your help !

Last seen on 20:29, 16. Feb 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I'm so silly ... I forget to…
Thu, 01/27/2022 - 16:18

I'm so silly ...

I forget to subscribe event so the packet was never registered :/

Last seen on 17:48, 19. May 2022
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Did you ever get this to…
Thu, 03/10/2022 - 22:38

Did you ever get this to work and if so could you show others how to get the text field to work on servers.