asanetargoss / Changeling

Shapeshifting mod and morphing API for Minecraft
https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2656333-asanetargoss-miscellaneous-mods-changeling-and
Other
5 stars 2 forks source link

Crash/Kick with Slime Blocks and Iron Golem morph (caused by exponential gravity) #18

Closed James103 closed 4 years ago

James103 commented 4 years ago

See mchorse/metamorph#206 (reposted here because of same root cause)

When you are morphed as an Iron Golem, some weird things happen in regards to gravity and motion:

  1. If you start bouncing on a Slime Block from high enough (about 20 blocks), you will bounce exponentially higher with each subsequent bounce. This reaches a point where you will lag very severely at the end of each bounce (as in several seconds per frame) and eventually crash and/or kick.

  2. To fall from 10,000 blocks only takes twice as long as to fall from 100 blocks for you, compared to 10x longer for others. To fall from 100 million blocks only takes four times as long as to fall from just 100 blocks, compared to 1000x longer for others. This does not make sense at all.

Both of those things are caused by the following code below, which, multiplies the motion instead of adding to it every tick. There are a few possible solutions to this:

  1. Regular gravity, but fluids like water don't slow you down vertically as much.
  2. Have the exponential growth taper off the closer you get to a set terminal velocity.
  3. Regular gravity, but stronger than normal, with the jump strength increased to compensate.

https://github.com/asanetargoss/Changeling/blob/3208f2074ad466e74598c077441746668a1aeba7/src/main/java/mchorse/vanilla_pack/morphs/IronGolemMorph.java#L20-L29

James103 commented 4 years ago

I've talked with @mchorse about this, and he said that my second idea would be a perfect solution to this, with my third solution being a possible alternative.

The code for the second idea would be as follows:

if (target.motionY < 5)
{
    target.motionY *= (1.1 - target.motionY / 50.0);
}

Which would replace: https://github.com/asanetargoss/Changeling/blob/3208f2074ad466e74598c077441746668a1aeba7/src/main/java/mchorse/vanilla_pack/morphs/IronGolemMorph.java#L29

As for my third idea, since a gravity of 0.10 meters per tick squared supposedly still allows jumping 1 meter despite a 25% increase over standard gravity (0.08 meters per tick squared), either the gravity should be increased by 0.02 (target.motionY -= 0.02;) or the gravity multiplied by 1.25.

I'm still waiting for @asanetargoss on what would be the best possible solution to this.

asanetargoss commented 4 years ago

As per https://github.com/mchorse/metamorph/issues/206 , this is fine, waiting on McHorse to decide if survival-related code contributions should target Changeling only (and machinima-related code Metamorph only); would hopefully make our git sorcery a bit simpler and changes would make their way to the other mod eventually.

asanetargoss commented 4 years ago

A new version of Changeling has been released on GitHub with the fix:

https://github.com/asanetargoss/Changeling/releases

I decided to postpone important maintenance, because I want to get a build up before McHorse's 1.12-only version of McLib gets released, and the possible confusion which could result from that.

James103 commented 4 years ago

I have tested this, a terminal velocity of approximately 100 m/s is reached while morphed as an Iron Golem, compared to 78.4 m/s for others. Jump height is about 1.1 m. No crash/kick is made.