Jump to content

[1.14.4][SOLVED] request server side data for gui


Recommended Posts

Posted (edited)

I want to display a double value from a server side player capability on one of my container screens and possibly other screens in the future. what is the best way to access this data from the container screen? would there be overlap if two players were using the same container, or are screens separate to each player?

 

[SOLUTION]

wherever the server is changing the value, send a packet to the client side that then uses "Minecraft.getInstance().player" to access the client side playaer capability and set the value there.
 

Edited by andGarrett
Posted
Just now, andGarrett said:

or are screens separate to each player

Screens are separate for each player and so are containers I think.

Just now, andGarrett said:

would there be overlap if two players were using the same container

No because you would be getting it from the client player.

1 minute ago, andGarrett said:

what is the best way to access this data from the container screen?

Sync the specific data to the client whenever it changes if it can change while in the container, or if it can't change when in the container sync it when the container opens. With your own packet.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
14 hours ago, Animefan8888 said:

Sync the specific data to the client whenever it changes if it can change while in the container, or if it can't change when in the container sync it when the container opens. With your own packet.

how would I get access to the client side player entity from the server side? I could pass the client side player entity to the packet, but then I don't know how I would encode/decode the player entity. I don't see any PacketBuffer read/write methods for Player entities.

Posted
4 minutes ago, andGarrett said:

how would I get access to the client side player entity from the server side?

You wouldn't. I'm not sure what you mean. You have a packet that goes from server to client right? Then the packet is handled on the client and you can use Minecraft.getInstance().player

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
1 hour ago, Animefan8888 said:

You wouldn't. I'm not sure what you mean. You have a packet that goes from server to client right? Then the packet is handled on the client and you can use Minecraft.getInstance().player

"Minecraft.getInstance().player" is the missing piece to this puzzle, thank you! now I can access the client side player's capability at the same time I'm accessing the server side player capability and update both at the same time. Then I will use the client side capability for displaying the value on my store screen.

Posted
19 hours ago, diesieben07 said:

Unless you have a very weird definition of "at the same time", this is not true!

The client and server run on different threads. There is no way to safely access client and server player at the same time.

in one of my methods that gets run on the server side, I set the the server side value for the players capability, then on the very next line, I use "Minecraft.getInstance().player" to access the client side player capability to set that value. technically that's not at the "same time", but because there is no code in between the two actions, it's close enough to the same time. I guess I should have said that I am changing it in the same method.

Posted
Just now, andGarrett said:

in one of my methods that gets run on the server side, I set the the server side value for the players capability, then on the very next line, I use "Minecraft.getInstance().player" to access the client side player capability to set that value. technically that's not at the "same time", but because there is no code in between the two actions, it's close enough to the same time. I guess I should have said that I am changing it in the same method.

No no no don't do that. It will crash the dedicated server and you are reaching across logical sides. You need to send a packet and in the handling method of the packet you use Minecraft.getInstance().player.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
2 hours ago, Animefan8888 said:

No no no don't do that. It will crash the dedicated server and you are reaching across logical sides. You need to send a packet and in the handling method of the packet you use Minecraft.getInstance().player.

will do.

 

so I should always use packets to send data between logical sides? when you say "dedicated server", I take it you mean a server that is used for multiplayer and not simply the "logical server"?

Posted
Just now, andGarrett said:

so I should always use packets to send data between logical sides?

Yes. There are reasons such as LAN worlds, and the fact that they are on separate threads.

2 minutes ago, andGarrett said:

when you say "dedicated server", I take it you mean a server that is used for multiplayer and not simply the "logical server"?

Yes that is exactly what I mean. The DedicatedServer doesn't know about the Minecraft class at all. It doesn't exist. So using on a DedicatedServer will crash with a ClassNotFoundException.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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