#Trouble passing player position from the client to the server

22 messages · Page 1 of 1 (latest)

jagged vector
#

I've gotten part of network events figured out, but I can't figure out why the player's position isn't being passed to the server. It prints fine on the client, but prints undefined on the server, so something is being lost in translation when sendData is used...

//CLIENT (In startup scripts)
if (Platform.clientEnvironment) {
    ForgeEvents.onEvent("net.minecraftforge.client.event.ScreenEvent$Opening", event => {
        if (Client.player) {

            Client.player.tell("Something happened with the screen, ayo? " + event.currentScreen + " -> " + event.newScreen)

            let startPos = Client.player.position()

            Client.player.tell(startPos)
            
            //SEND MESSAGE TO SERVER
            Client.player.sendData('packetname', { positioningData: startPos })


            }
    })
}

//SERVER
NetworkEvents.dataReceived('packetname', event =>{

    const { positioningData } = event.data

    //PRINT DEBUGGING
    console.log('Received client packet')
    console.log(positioningData)

})
paper stratusBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

distant wasp
#

maybe try sending the x y z instead

#

you can't send arbitrary objects using packets (at least when making mods, idk if kjs serializes it)

#

wait have you tried logging the event.data?

muted kestrelBOT
#

Paste version of config.js from @distant wasp

distant wasp
muted kestrelBOT
#

Paste version of config.js from @distant wasp

distant wasp
#

first is client script, second is server script

#
  • player logs in
  • server sends client an empty packet
  • client gets that packet
  • client checks some arbitrary config value (it was for a quest)
  • client sends a packet with a boolean to the server
  • server gets that packet
  • server checks the boolean, and does stuff
#

you can probably only send primitives and strings

#

let me check actually

#

hm ok so no

storm swan
#

isnt it event.player.senddata?

jagged vector
#

Gonna try splitting the pos into x, y, z after this next test

jagged vector
#

Nvm, suffering from sensory overload. Be back a bit later

#

Too loud where I am

jagged vector
#

And we're back at it

vestal mural
#

at STARTUP

//STARTUP
if (Platform.isClientEnvironment()){
  ForgeEvents.onEvent("net.minecraftforge.client.event.ScreenEvent$Opening", event => {
    if (Client.player) {
      Client.player.tell("Something happened with the screen, ayo? " + event.currentScreen + " -> " + event.newScreen)
      let startPos = Client.player.blockPosition()
      Client.player.tell("Client: " + startPos)
      //SEND MESSAGE TO SERVER
      Client.player.sendData('packetname', { positioningData: startPos.asLong() })
    }
  })
}

at SERVER

NetworkEvents.dataReceived('packetname', event =>{
  const { positioningData } = event.data
  //PRINT DEBUGGING
  console.log('Received client packet')
  event.player.tell("Server: " + BlockPos.of(positioningData))
})
jagged vector
#

Oh wow, ty, trying it out

#

It works... Thank you so much