Started by
nathyperfort
on
Topic category: Help with Minecraft modding (Java Edition)
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 now without custom network packet to sync the client contents to the server
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 !
I'm so silly ...
I forget to subscribe event so the packet was never registered :/
Did you ever get this to work and if so could you show others how to get the text field to work on servers.
Yes, It did work. I'm posting an example.
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
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
...
Then, Create a custom Element with the following code https://pastebin.com/L9sHqTdz
Make an empty procedure called OnInit with https://pastebin.com/9dvaRXcS
Procedure to convert to player vars https://i.ibb.co/HCk7XMW/procedure.png
Good Luck
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
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