Jump to content

Recommended Posts

Posted

im trying to fix a few things for a custome toilet whit running water
in this moment i alredy have keybinds and custome packages to be sended to the server side and thas working 

now im trying to send a package from the server side to the client side

soo ijust copy paste the server package code and change in the declaration NetworkDirection.PLAY_TO_SERVER to NetworkDirection.PLAY_TO_CLIENT
seems it dont trow errors but don't works  still the messages gets in the console so its running 
i notice in this line the player is null 

	ServerPlayer player = context.getSender();
System.out.print( ((player != null)? player.getDisplayName() : "NullPlayer" ) ); //this returns nullPlayer 
	

##############################

i need a guide on how to send a package form server to client side 
or 
a way to get the player entity form the local world i remember in 1.8 you have to do something like 

Minecraft mc = new Minecraft()

Player pe = mc.getThePlayer();

 

....

half working code i made just guessing 

  Reveal hidden contents

 

 

 

thanks for your time

 

 

Posted

There are literally hundreds of threads in this forum where this is discussed because people do it wrong.

Use Minecraft.getInstance() on the client then get what state you want.

But you should put all client code in a separate class otherwise you are very likely going to crash the game on a dedicated server.

https://docs.minecraftforge.net/en/latest/networking/simpleimpl/#handling-packets

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)
  On 5/28/2023 at 8:16 AM, warjort said:

There are literally hundreds of threads in this forum where this is discussed because people do it wrong.

Use Minecraft.getInstance() on the client then get what state you want.

But you should put all client code in a separate class otherwise you are very likely going to crash the game on a dedicated server.

https://docs.minecraftforge.net/en/latest/networking/simpleimpl/#handling-packets

Expand  
  Quote

No i dont get how to make it work 
public static void handle(MyClientMessage msg, Supplier<NetworkEvent.Context> ctx) {}

this costume class MyClientMessage  what it is what requires,  Kapnejoe tutorial just create a variable class <MSG> but it i make it this way it just red lines in intellij 

public static <MSG> void sendToPlayer(MSG message, ServerPlayer pe) {} <-msg is a generic class


also there's no example on how to the the player instance in the local word 

i need and instance of player to get from it the level and do the stuff 

is there a working example specifically made for 1.19.4 i can use to guide myself ??

Captura-de-pantalla-de-2023-05-28-07-03-

Expand  

 

 

 

  Quote



 

Expand  

 

Edited by perromercenary00

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.