Szum123321 / elytra_swap

Automatic elytra replacement with chestplace and more
https://www.curseforge.com/minecraft/mc-mods/elytra-swap
GNU General Public License v3.0
3 stars 2 forks source link

fixed horizontal mode #28

Open Tofugrass opened 3 years ago

Tofugrass commented 3 years ago

can I test this build as soon as possible and get back to you? I think this implementation of horizontal mode is better than easy elytra.

Szum123321 commented 3 years ago

But... That's basically what it was before...

The main point of our disagreement was that I wasn't multiplying y component the speed update vector by the sine of player's pitch.

Also are you decreasing player's launch speed in horizontal mode? I found that you should rather increase it to be useful.

Tofugrass commented 3 years ago

yes after a lot of testing i agree with you on the initial launch angle being fine.

and the low velocity shouldnt matter because we are engaging the wings immediately, but it is still configurable so i can test it,

Tofugrass commented 3 years ago

having the wings being automatically engaged for the player in horizontal mode is a huge change already and would make it act drastically different from vertical mode

Szum123321 commented 3 years ago

Actually, in that can I don't think we need horizontal mode at all, as automatically inserting elytra would be just a better solution.

I think I'm going to close this pr, remove few las commits and add the insertion think then.

Is that okay with you?

Tofugrass commented 3 years ago

wait, before u undo everything, could at least just add the jump to horizontal mode, and send me a test build. i think itll be perfect. u dont have to change anything else.

Tofugrass commented 3 years ago

imagine ur in a small house and u want to fly out of the window. it wouldnt be possible with only vertical mode, because u would smash ur head on the ceiling every time. with horizontal mode, u can fly straight out of the window easily.

i think horizontal mode adds a lot of value to the mod.

Tofugrass commented 3 years ago

and the reason why i preserved your launch angle, is because it is immediately overwritten when we do the jump. so its not that ur original launch angle was perfect, its moreso the fact that it immediately gets overwritten by vanilla mechanics.

and i dont understand what you mean by automatically inserting elytra. i am wearing elytra at all times, i just want to takeoff with right click without smashing the spacebar.

Tofugrass commented 3 years ago

ur mod makes it super easy to modify redstone contraptions, because ur mod allows the player to fit into one high spaces without jumping, but only in horizontal mode. ur mod is sick bro but it need horizontal mode.

Szum123321 commented 3 years ago

Sorry, but I don't have much time left today. We'll have to continue tomorrow.

Tofugrass commented 3 years ago

i dont see why u want to revert it. you made horizontal mode disabled by default so all you did was add additional functionality. having additional functionality is good.

Tofugrass commented 3 years ago

the way the mod works, after the player uses the firework, the player has to jump to takeoff. since the player pretty much has to jump every time, I changed horizontal mode to automatic jump mode in this pull request, (or automatic takeoff mode). it even keeps the same launch angle as vertical mode, all it does is add a jump. im sure many of ur users would find it extremely useful, since the players currently have to jump manually everytime.

plus its already done, you just have to rebuild.

having the player jump by themselves is fine in most situations, but in order to give the player enough time to jump on high ping, you have to set the kickSpeed to a fairly large number (>1,2).

setting the kickspeed to accommodate high ping causes issues

  1. player can not takeoff with a roof above them (they hit their head and land instantly, giving no time to jump)
  2. player can not fly through a 1x1 hole they are looking at (because they fly up first, so then they are above the hole)
  3. player travels farther than they would (because of the kickspeed)

i already fixed these issues in this pull request in automatic jump mode. i set the kickspeed to a lower value, and added the automatic jump. by having the automatic jump, the wings engage instantly, so we can have a very low velocity, just enough to get the player of the ground for the jump to engage flight.

i think having automatic jump mode would be great. dont u already jump after every firework?

Szum123321 commented 3 years ago

Ok, so I spent some time on the TakeoffHandler and here's what I came up with:

public static void sendUpdate(World world, PlayerEntity player, Hand hand) {
        if(!ElytraSwap.CONFIG.horizontalMode.getState() && !checkSpaceOverPlayer(player, ElytraSwap.CONFIG.requiredHeightAbovePlayer))
            return;

            ServerSidePacketRegistry.INSTANCE.sendToPlayer(player,
                    new EntityVelocityUpdateS2CPacket(player.getEntityId(),
                            new Vec3d(-Math.sin(Math.toRadians(player.yaw)) * ElytraSwap.CONFIG.kickSpeed,
                                    ElytraSwap.CONFIG.kickSpeed * (ElytraSwap.CONFIG.horizontalMode.getState() ? -Math.sin(Math.toRadians(player.pitch)) : 1),
                                    Math.cos(Math.toRadians(player.yaw)) * ElytraSwap.CONFIG.kickSpeed
                            )
                    )
            );

        world.spawnEntity(new FireworkRocketEntity(world, player.getStackInHand(hand), player));

        if(ElytraSwap.CONFIG.horizontalMode.getState()) {
            if(ElytraSwap.CONFIG.globalSwapEnable.getState()) {
                InventoryHelper.replaceChestplateWithElytra(new FlatInventory(player));
                player.startFallFlying();
            }

            player.jump();
        }
    }

Form my test I seem like decreasing kick speed would give player too litle velcity to successfully takeoff

Tofugrass commented 3 years ago

Another way to fix the issue besides increasing velocity is to have a pause before the jump.

For testing purposes it would be nice to have it be configurable, but for main release we should pick the best one from testing.

I think you need to add this https://www.javatpoint.com/sleep()-method.

From my testing with a mouse macro, the takeoff works well with 110 ms.

Tofugrass commented 3 years ago

thats also why I made the launch angle vertical again, so the player has an easier time taking off.

Tofugrass commented 3 years ago

I merged this branch with your 2.x master and then added the sleep method. Can I get an updated testing build please?

Szum123321 commented 3 years ago

Using sleep is a horrible idea. Remember that all of this will run on main server thread. Pausing it would dramatically decrease TPS count