Hey guys, I'm trying to get started with scripting my own mods. But I'm having trouble working with built-in minecraft api events.
Here is the test code. It is just a client script that should print the coordinates of the block the reticle is looking at. I've actually copy-pasted the code from the api wiki so I'm extra confused as to why it isn't working. I have two methods for displaying a message and neither show up. Could I be using them incorrectly in some way? I also tried placing a this.broadcastEvent("minecraft:display_chat_event", "test"); in the update function and that would also not display a message. I don't receive any errors, the messages just don't display.
Does anyone have any idea of what I could be doing wrong here? Any help is appreciated.
Edit:
I figured out what the issued was, you cannot simply pass a string as the parameter to the broadcastEvent("minecraft:display_chat_event") function. It requires the proper event data object to be initialized first and the string added to the message property of the data property of the object. The documentation is incorrect at gameapedia, I have attempted to make corrections. I will leave my non working code here next to a set of working code to help anyone who may come across this.
Hey guys, I'm trying to get started with scripting my own mods. But I'm having trouble working with built-in minecraft api events.Here is the test code. It is just a client script that should print the coordinates of the block the reticle is looking at. I've actually copy-pasted the code from the api wiki so I'm extra confused as to why it isn't working. I have two methods for displaying a message and neither show up. Could I be using them incorrectly in some way? I also tried placing a this.broadcastEvent("minecraft:display_chat_event", "test"); in the update function and that would also not display a message. I don't receive any errors, the messages just don't display.Does anyone have any idea of what I could be doing wrong here? Any help is appreciated.Edit:
I figured out what the issued was, you cannot simply pass a string as the parameter to the broadcastEvent("minecraft:display_chat_event") function. It requires the proper event data object to be initialized first and the string added to the message property of the data property of the object. The documentation is incorrect at gameapedia, I have attempted to make corrections. I will leave my non working code here next to a set of working code to help anyone who may come across this.
Example of NOT working code (original post)
Example of WORKING code
Client.js:
Server.js: