Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pitch40 to more efficient angles #5221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public class ElytraFly extends Module {
public final Setting<Double> pitch40rotationSpeed = sgGeneral.add(new DoubleSetting.Builder()
.name("pitch40-rotate-speed")
.description("The speed for pitch rotation (degrees per tick)")
.defaultValue(4)
.defaultValue(15)
.min(1)
.sliderMax(6)
.sliderMax(20)
.visible(() -> flightMode.get() == ElytraFlightModes.Pitch40)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class Pitch40 extends ElytraFlightMode {
private boolean pitchingDown = true;
private int pitch;
private float pitch;

public Pitch40() {
super(ElytraFlightModes.Pitch40);
Expand All @@ -22,18 +22,33 @@ public void onActivate() {
if (mc.player.getY() < elytraFly.pitch40upperBounds.get()) {
elytraFly.error("Player must be above upper bounds!");
elytraFly.toggle();
} else if (mc.player.getY() - 40 < elytraFly.pitch40lowerBounds.get()) {
elytraFly.error("Player must be at least 40 blocks above the lower bounds!");
elytraFly.toggle();
}

pitch = 40;
pitch = 32.0F;
}

@Override
public void onDeactivate() {}
/**
* Create a random pitch around `pitch` that is within +/- bound/2
* @param pitch the input pitch
* @param bound the amount of variance
* @return the changed pitch
*/
private float randPitch(float pitch, float bound) {
return (float) (pitch + (bound * (Math.random() - 0.5)));
}

@Override
public void onTick() {
super.onTick();

/*
When descending, look at 32-33 deg
When ascending, look up at -49 at 10*pitch speed, then lower at 0.5 deg/tick until at 32-33
*/

if (pitchingDown && mc.player.getY() <= elytraFly.pitch40lowerBounds.get()) {
pitchingDown = false;
}
Expand All @@ -42,15 +57,16 @@ else if (!pitchingDown && mc.player.getY() >= elytraFly.pitch40upperBounds.get()
}

// Pitch upwards
if (!pitchingDown && mc.player.getPitch() > -40) {
pitch -= elytraFly.pitch40rotationSpeed.get();
if (!pitchingDown) {
pitch -= randPitch(elytraFly.pitch40rotationSpeed.get().floatValue(), 3.0F);

if (pitch < -40) pitch = -40;
if (pitch < -49.0) {
pitch = -49.0F;
pitchingDown = true;
}
// Pitch downwards
} else if (pitchingDown && mc.player.getPitch() < 40) {
pitch += elytraFly.pitch40rotationSpeed.get();

if (pitch > 40) pitch = 40;
} else if (pitch < 32.0) {
pitch += randPitch(0.5F, 0.125F);
}

mc.player.setPitch(pitch);
Expand Down