Argent-Matter / gcyr

Gregicality Rocketry
https://modrinth.com/mod/gcyr
GNU Lesser General Public License v3.0
17 stars 7 forks source link

fix rocket movement in takeoff and landing #26

Closed jmoiron closed 3 months ago

jmoiron commented 3 months ago

This should fix the rocket parts of #25, and general problems people have had with rockets.

After a lot of confusion, tracing, debugging, and looking at Ad Astra's code (MIT licensed), I noticed that those rockets run their flight tick on both client and server.

The rules around player movement are apparently complicated. Generally, player movement is in the client and entity movement is on the server. When the player is a "controlling passenger" (horse, boat, etc), the entity movement is also controlled by the client, but when they are not (pig w/ stick+carrot) then it's server side.

This changeset modifies the rocket entity tick to ensure that flight movement (including landing the rocket) is run in both client and server consistently. I think this makes it safe for rockets w/ multiple passengers, but I'll need some help testing that.

In the end, the main issue was that consumeFuel() would not succeed on the client until it had received some kind of sync packet from the server. Still do not know 100% what the nature of that packet was, but the same failure also kept player interaction from working reliably in fall(). This is the only way I can think of that explains the varying delays in takeoff time and the flakiness trying to slow down the rocket on the other side, as evidenced by my lunar "landing site":

2024-03-24_23 23 45

Now, consumeFuel() is estimated on the client side using a sync'd fuel amount + recipe duration, which is still controlled on the server. Rocket speed is tracked externally to the entity's movement vector to make takeoff more consistent. There are a few other organizational changes that were mostly for better debuggability.

I've also changed the fuel tank drain to use the same value as it's being tested for, rather than one which was not impacted by the fuel recipe's duration. Rocket fuel is supposedly ~5x more efficient than Diesel, but they would drain at the same rate.

Also, a small fix to use the Diesel fluid type in the Diesel recipe.