-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use creative fly instead of custom fly
- Loading branch information
1 parent
fc3c9e1
commit 2632d6e
Showing
1 changed file
with
30 additions
and
33 deletions.
There are no files selected for viewing
63 changes: 30 additions & 33 deletions
63
src/main/java/de/mc8051/clientenhancements/client/Flying.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
package de.mc8051.clientenhancements.client; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.entity.player.PlayerAbilities; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
public class Flying { | ||
|
||
int toggle = 0; | ||
int MAX_SPEED = 3; | ||
double FALL_SPEED = -0.04; | ||
double ACCELERATION = 0.1; | ||
|
||
boolean switchedState = false; | ||
|
||
public void tick(MinecraftClient client) { | ||
if (client.player != null && ClientEnhancementsClient.getKeyBindingController().getState(KeyBindingController.FLY)) { | ||
boolean jumpPressed = client.options.jumpKey.isPressed(); | ||
boolean forwardPressed = client.options.forwardKey.isPressed(); | ||
boolean leftPressed = client.options.leftKey.isPressed(); | ||
boolean rightPressed = client.options.rightKey.isPressed(); | ||
boolean backPressed = client.options.backKey.isPressed(); | ||
|
||
Entity entity = client.player; | ||
if (client.player.hasVehicle()) return; | ||
|
||
final boolean anyMovement = forwardPressed || leftPressed || rightPressed || backPressed; | ||
Vec3d velocity = entity.getVelocity(); | ||
Vec3d newVelocity = new Vec3d(velocity.x, -FALL_SPEED, velocity.z); | ||
if (forwardPressed) newVelocity = client.player.getRotationVector().multiply(ACCELERATION); | ||
if (leftPressed) { | ||
newVelocity = client.player.getRotationVector().multiply(ACCELERATION).rotateY((float) (Math.PI / 2)); | ||
newVelocity = new Vec3d(newVelocity.x, 0, newVelocity.z); | ||
} | ||
if (rightPressed) { | ||
newVelocity = client.player.getRotationVector().multiply(ACCELERATION).rotateY((float) -(Math.PI / 2)); | ||
newVelocity = new Vec3d(newVelocity.x, 0, newVelocity.z); | ||
if (client.player != null) { | ||
ClientPlayerEntity player = client.player; | ||
boolean inFlyMode = player.isCreative() || player.isSpectator(); | ||
|
||
if (ClientEnhancementsClient.getKeyBindingController().getState(KeyBindingController.FLY)) { | ||
if (!switchedState) switchedState = true; | ||
player.getAbilities().allowFlying = true; | ||
|
||
if (player.hasVehicle()) return; | ||
if (inFlyMode) return; | ||
|
||
final Vec3d velocity = player.getVelocity(); | ||
if (toggle == 0) { | ||
player.setVelocity(new Vec3d( | ||
velocity.x, FALL_SPEED - velocity.y, velocity.z | ||
)); | ||
} | ||
|
||
if (toggle == 0 || velocity.y < FALL_SPEED) toggle = 40; | ||
toggle--; | ||
} else if (switchedState) { | ||
switchedState = false; | ||
PlayerAbilities abilities = player.getAbilities(); | ||
|
||
abilities.flying = inFlyMode && !player.isOnGround(); | ||
abilities.allowFlying = inFlyMode; | ||
} | ||
if (backPressed) newVelocity = client.player.getRotationVector().negate().multiply(ACCELERATION); | ||
newVelocity = new Vec3d(newVelocity.x, (toggle == 0 && newVelocity.y > FALL_SPEED) ? FALL_SPEED : (anyMovement ? newVelocity.y : 0), newVelocity.z); | ||
entity.setVelocity(newVelocity); | ||
|
||
if(anyMovement) { | ||
if (ACCELERATION < MAX_SPEED) ACCELERATION += 0.1; | ||
} else if (ACCELERATION > 0.2) ACCELERATION -= 0.2; | ||
|
||
if(toggle == 0 || newVelocity.y <= FALL_SPEED) toggle = 40; | ||
toggle--; | ||
} | ||
} | ||
} |