Get Textfield on server

Started by nathyperfort on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Get Textfield on server

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 !

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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 !

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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 :/

Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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.

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, It did work. I'm…
Wed, 10/05/2022 - 19:40

Yes, It did work. I'm posting an example.

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
On world tick update, a…
Wed, 10/05/2022 - 19:40

On world tick update, a procedure will run converting the list values (set by the packet) into player variables.

NOTE : This example works with an old mcreator generator (1.16.5 for 2021.2)

You'll need to : replace the net.mcreator.modid , the YourMod, and the YourGui classes by yours.

First create a custom element called CustomPacketHandler. Here is the code : https://pastebin.com/fJQPDnGa

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Then find the gui you want…
Wed, 10/05/2022 - 19:40

Then find the gui you want to get the textfield input from, and select edit (the Window part). You'll need to lock this element.

Ichange your TextField field from private to public. In my example it is called Number :
public class YourGuiWindow ...
    ...
    public TextFieldWidget Number -- changed to public
    ...

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hi, in your code for the…
Thu, 08/03/2023 - 01:30

Hi, in your code for the custom packet handler you have a global array list called "tmpInputList" that you mention you used a plugin to install. Was it goldirons array list plugin? if so how did you add the global array list variable? Thanks

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hi, sorry for late reply…
Thu, 05/09/2024 - 10:48

Hi, sorry for late reply. Yes i use Goldorion's array list plugin, more precisely the version 2.1 from https://github.com/Goldorion/Array-Lists-MCreator/releases/download/2.1/Array-Lists.zip (Mcreator 2021.2).

I added this variable in the Variables tab, with scope GLOBAL_SESSION. Also sorry for the low resolution image, here's another : https://i.ibb.co/L6pnfr0/procedure.png