[Questions] [Addon development] A bunch of different questions
slava110 opened this issue ยท 2 comments
So I'm developing a mod and I'm using your mod as dependency... And I've got multiple questions I wanted to ask
- Is there any safe way to teleport vehicle entity? Can I just use
setPositionAndUpdate
? - Is it possible to block car controls for player in the vehicle?
- Is it possible to block seat changing in the vehicle?
- Is it save to serialize and then deserialize vehicle entity? I should set another UUID for this entity after deserialization, right?
Would be easier to go back and forth on Discord, but here goes.
When you say teleport, I'm assuming you mean within the same world. Cross-world teleportation is a whole nother animal. For teleporting in the current dimension, you'd want to simply change the "position" and "prevPosition" values. You'd then take that delta you applied, and set it to all clients to let them know the vehicle moved. What you don't want to do is set the vehicle to a position on the server, and send that raw value to the client. MTS operates off a motion-syncing system, where each motion applied on the server is sent to the client for it to match. And if you manually set the position of the vehicle on the client, then there's a chance the vehicle will get de-synced from it's motion steps. Also, you don't want to call "addToServerDeltas" when you aplly this teleportation call, because if you do, MTS will interperate it as a syncing packet. In fact, if you add it to the vehicle's motion that's also bad, because you'll cause MTS to think the vehicle moved really quickly, which will cause tons of lag for collision checks. But, as long as you don't modify the motion, the client/server delta, and apply the position as an addition to the existing position, rather than a hard-set, you should be just fine.
Blocking car controls is as simple as finding a way to block the call to ControlSystem. Exactly how you do this is up to you and what conditions you want to make the controls be blocked.
Blocking seat changing is more complex, in that you'd have to keep players from clicking the seats. Again, this depends on what you're trying to do, and why the seat would need to be blocked. Currently, seats just check if there's a rider in them, and if so, they're blocked. MTS also checks if the vehicle is locked before making players ride in seats, so that's another way to do things and similar system you could use.
Not sure what you're wanting to do with serialization. In theory though, yes. Proper serialization dictates that the UUID is saved, as that's what makes it unique, but should you want to clone the vehicle and not make it the same vehicle, then you would need to strip the UUID from the saved data so it doesn't get re-assigned to the new vehicle and it's re-created. After that, the general construction methods should handle the rest.