#Can you set the owner of a projectile?

4 messages · Page 1 of 1 (latest)

obtuse condor
#

ANSWER: Yes you can, by using the .setOwner() method of your projectile entity. in my case, that would be projectile.setOwner(event.player)

Original Question:
To make a magic spells system, I'm spawning spell projectiles using event.level.createEntity(). but because of that they don't have an owner. I've tried several shots at changing the arrow's nbt data both before and after spawn, but it does not work.

Current attempt using arrows as projectiles:

ItemEvents.rightClicked('arrow',event => {
    let p = event.player
    let {x,y,z,lookAngle} = p
    let proj = event.level.createEntity('minecraft:arrow')
    proj.nbt.Owner = p.uuid
    proj.setPosition(x,y+p.eyeHeight*0.7,z)
    proj.noGravity = true
    proj.addDeltaMovement(Vec3d(lookAngle.x(),lookAngle.y(),lookAngle.z()))
    proj.spawn()
    p.tell(proj.nbt)
})```
compact cedarBOT
#

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

obtuse condor
#

I get no error message of any kind, but the nbt of the arrow just doesn't have an Owner field as it wasn't shot from a weapon

#

Never mind, the solution was to set the owner using the setOwner() method. This did not show up from ProbeJS, I discovered it by asking Gemini (wtf, how does it know?) to solve this problem. When I typed the setOwner() method, it seems like it's only a method of fishing hooks, not other entities?
Anyway, issue resolved.