mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-05-02 11:34:03 +02:00
Change flight to 'Hold to Sprint' mode at all times & fix not boost unless flying forward
This commit is contained in:
parent
3923a65cd8
commit
6e2625c737
src/main
java/chylex/bettercontrols
config
gui
mixin
player
resources
@ -19,7 +19,6 @@ public final class BetterControlsConfig{
|
||||
public boolean sneakingMovesCameraSmoothly = true;
|
||||
|
||||
public final KeyBindingWithModifier keyToggleFlight = new KeyBindingWithModifier("key.bettercontrols.toggle_flight");
|
||||
public SprintMode sprintModeWhileFlying = SprintMode.TAP_TO_START;
|
||||
public boolean disableFlightInertia = false;
|
||||
public boolean disableChangingFovWhileFlying = false;
|
||||
public boolean flyOnGroundInCreative = false;
|
||||
|
@ -40,7 +40,6 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
||||
Json.setBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);
|
||||
|
||||
Json.writeKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
||||
Json.setEnum(obj, "Flight.SprintMode", cfg.sprintModeWhileFlying);
|
||||
Json.setBool(obj, "Flight.DisableInertia", cfg.disableFlightInertia);
|
||||
Json.setBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
||||
Json.setBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||
@ -79,7 +78,6 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
||||
cfg.sneakingMovesCameraSmoothly = Json.getBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);
|
||||
|
||||
Json.readKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
||||
cfg.sprintModeWhileFlying = Json.getEnum(obj, "Flight.SprintMode", cfg.sprintModeWhileFlying, SprintMode.class);
|
||||
cfg.disableFlightInertia = Json.getBool(obj, "Flight.DisableInertia", cfg.disableFlightInertia);
|
||||
cfg.disableChangingFovWhileFlying = Json.getBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
||||
cfg.flyOnGroundInCreative = Json.getBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||
|
@ -121,11 +121,6 @@ public class BetterControlsScreen extends SettingsScreen{
|
||||
|
||||
y += ROW_HEIGHT;
|
||||
|
||||
generateLeftSideText(y, elements, text("Sprint Key Mode While Flying"));
|
||||
elements.add(new CycleButtonWidget<>(col2(1), y, COL2_W, SPRINT_MODE_OPTIONS, cfg.sprintModeWhileFlying, value -> cfg.sprintModeWhileFlying = value));
|
||||
|
||||
y += ROW_HEIGHT;
|
||||
|
||||
generateLeftSideText(y, elements, text("Disable Flight Inertia"));
|
||||
elements.add(new BooleanValueWidget(col2(1), y, COL2_W, cfg.disableFlightInertia, value -> cfg.disableFlightInertia = value));
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
public abstract class HookPlayerFlightSpeed extends LivingEntity{
|
||||
protected HookPlayerFlightSpeed(final EntityType<? extends LivingEntity> type, final World world){
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "travel",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSprinting()Z"),
|
||||
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerAbilities;getFlySpeed()F"))
|
||||
)
|
||||
private boolean disableVanillaSprintBoost(final PlayerEntity player){
|
||||
return false;
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ final class FlightHelper{
|
||||
private FlightHelper(){}
|
||||
|
||||
private static final float BASE_FLIGHT_SPEED = 0.05F;
|
||||
private static final float BASE_FLIGHT_SPEED_SPRINT_MP_INV = 0.5F; // sprinting doubles speed in PlayerEntity.travel
|
||||
private static final float BASE_VERTICAL_VELOCITY = 3F;
|
||||
|
||||
private static BetterControlsConfig cfg(){
|
||||
@ -22,18 +21,18 @@ final class FlightHelper{
|
||||
return cfg().flyOnGroundInCreative && player.isCreative() && player.abilities.isFlying;
|
||||
}
|
||||
|
||||
static float getFlightSpeed(final ClientPlayerEntity player){
|
||||
static float getFlightSpeed(final ClientPlayerEntity player, final boolean boost){
|
||||
if (player.isCreative()){
|
||||
if (player.isSprinting()){
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpCreativeSprinting * BASE_FLIGHT_SPEED_SPRINT_MP_INV;
|
||||
if (boost){
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpCreativeSprinting;
|
||||
}
|
||||
else{
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpCreativeDefault;
|
||||
}
|
||||
}
|
||||
else if (player.isSpectator()){
|
||||
if (player.isSprinting()){
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpSpectatorSprinting * BASE_FLIGHT_SPEED_SPRINT_MP_INV;
|
||||
if (boost){
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpSpectatorSprinting;
|
||||
}
|
||||
else{
|
||||
return BASE_FLIGHT_SPEED * cfg().flightSpeedMpSpectatorDefault;
|
||||
@ -44,9 +43,9 @@ final class FlightHelper{
|
||||
}
|
||||
}
|
||||
|
||||
static float getExtraVerticalVelocity(final ClientPlayerEntity player){
|
||||
static float getExtraVerticalVelocity(final ClientPlayerEntity player, final boolean isSprinting){
|
||||
if (player.isCreative()){
|
||||
if (player.isSprinting()){
|
||||
if (isSprinting){
|
||||
return BASE_VERTICAL_VELOCITY * cfg().flightVerticalBoostCreativeSprinting;
|
||||
}
|
||||
else{
|
||||
@ -54,7 +53,7 @@ final class FlightHelper{
|
||||
}
|
||||
}
|
||||
else if (player.isSpectator()){
|
||||
if (player.isSprinting()){
|
||||
if (isSprinting){
|
||||
return BASE_VERTICAL_VELOCITY * cfg().flightVerticalBoostSpectatorSprinting;
|
||||
}
|
||||
else{
|
||||
|
@ -81,15 +81,7 @@ public final class PlayerTicker{
|
||||
((AccessClientPlayerFields)player).setTicksLeftToDoubleTapSprint(0);
|
||||
}
|
||||
|
||||
final SprintMode sprintMode;
|
||||
|
||||
if (FlightHelper.isFlyingCreativeOrSpectator(player)){
|
||||
sprintMode = cfg().sprintModeWhileFlying;
|
||||
}
|
||||
else{
|
||||
sprintMode = cfg().sprintMode;
|
||||
}
|
||||
|
||||
final SprintMode sprintMode = cfg().sprintMode;
|
||||
final boolean wasSprintToggled = OPTIONS.toggleSprint;
|
||||
final boolean isSprintToggled = toggleSprint.tick();
|
||||
|
||||
@ -160,8 +152,9 @@ public final class PlayerTicker{
|
||||
}
|
||||
|
||||
if (FlightHelper.isFlyingCreativeOrSpectator(player)){
|
||||
final float flightSpeed = FlightHelper.getFlightSpeed(player);
|
||||
final float verticalVelocity = FlightHelper.getExtraVerticalVelocity(player);
|
||||
final boolean boost = Key.isPressed(KEY_SPRINT);
|
||||
final float flightSpeed = FlightHelper.getFlightSpeed(player, boost);
|
||||
final float verticalVelocity = FlightHelper.getExtraVerticalVelocity(player, boost);
|
||||
|
||||
if (flightSpeed > 0F){
|
||||
player.abilities.setFlySpeed(flightSpeed);
|
||||
|
@ -18,6 +18,7 @@
|
||||
"HookControlsListWidget",
|
||||
"HookLoadGameOptions",
|
||||
"HookOpenScreen",
|
||||
"HookPlayerFlightSpeed",
|
||||
"HookStickyKeyBindingState"
|
||||
],
|
||||
"injectors": {
|
||||
|
Loading…
Reference in New Issue
Block a user