1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2025-04-11 21:15:43 +02:00

Update for Minecraft 1.21.4

This commit is contained in:
chylex 2025-01-29 18:45:20 +01:00
parent 464bd3bcb6
commit 2cb16b1b74
Signed by: chylex
SSH Key Fingerprint: SHA256:WqM8X/1DDn11LbYM0H5wsqZUjbcKxVsic37L+ERcF4o
9 changed files with 46 additions and 39 deletions
Fabric/src/main/java/chylex/bettercontrols/compatibility
NeoForge/src/main/java/chylex/bettercontrols
src/main/java/chylex/bettercontrols

View File

@ -3,11 +3,10 @@ package chylex.bettercontrols.compatibility;
import chylex.bettercontrols.gui.BetterControlsScreen;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.minecraft.client.Minecraft;
public class ModMenuSupport implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parentScreen -> new BetterControlsScreen(Minecraft.getInstance(), parentScreen);
return BetterControlsScreen::new;
}
}

View File

@ -2,19 +2,26 @@ package chylex.bettercontrols;
import chylex.bettercontrols.config.BetterControlsConfig;
import chylex.bettercontrols.gui.BetterControlsScreen;
import net.minecraft.client.gui.screens.Screen;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import javax.annotation.Nullable;
@Mod("bettercontrols")
public final class BetterControlsMod {
public BetterControlsMod() {
if (FMLEnvironment.dist == Dist.CLIENT) {
BetterControlsCommon.setConfig(BetterControlsConfig.load(FMLPaths.CONFIGDIR.get().resolve("BetterControls.json")));
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> BetterControlsScreen::new);
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> BetterControlsMod::createOptionsScreen);
}
}
private static BetterControlsScreen createOptionsScreen(final ModContainer modContainer, @Nullable final Screen parentScreen) {
return new BetterControlsScreen(parentScreen);
}
}

View File

@ -206,8 +206,8 @@ public class BetterControlsScreen extends OptionsSubScreen {
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
@SuppressWarnings("DataFlowIssue")
public BetterControlsScreen(final Minecraft mc, @Nullable final Screen parentScreen) {
super(parentScreen, mc.options, TITLE);
public BetterControlsScreen(@Nullable final Screen parentScreen) {
super(parentScreen, Minecraft.getInstance().options, TITLE);
}
@Override

View File

@ -70,13 +70,13 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
}
@Override
protected int getScrollbarPosition() {
protected int scrollBarX() {
return (width + ROW_WIDTH) / 2 + 4;
}
@Override
public boolean mouseScrolled(final double x, final double y, final double xAmount, final double yAmount) {
setScrollAmount(getScrollAmount() - yAmount * SCROLL_MULTIPLIER);
setScrollAmount(scrollAmount() - yAmount * SCROLL_MULTIPLIER);
return true;
}

View File

@ -4,23 +4,19 @@ import chylex.bettercontrols.player.PlayerTicker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.player.Abilities;
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(AbstractClientPlayer.class)
public abstract class HookClientPlayerFOV {
@Redirect(
method = "getFieldOfViewModifier",
at = @At(value = "INVOKE", target = "Ljava/lang/Float;isNaN(F)Z"),
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getWalkingSpeed()F"),
to = @At(value = "INVOKE", target = "Ljava/lang/Float;isInfinite(F)Z")
)
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getWalkingSpeed()F")
)
private boolean resetFOV(final float movementSpeed) {
private float overrideWalkingSpeed(final Abilities abilities) {
final LocalPlayer player = Minecraft.getInstance().player;
return (player != null && PlayerTicker.get(player).shouldResetFOV(player)) || Float.isNaN(movementSpeed);
return (player != null && PlayerTicker.get(player).shouldResetFOV(player)) ? 0F : abilities.getWalkingSpeed();
}
}

View File

@ -2,7 +2,6 @@ package chylex.bettercontrols.mixin;
import chylex.bettercontrols.player.PlayerTicker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.client.player.LocalPlayer;
import org.spongepowered.asm.mixin.Mixin;
@ -14,14 +13,15 @@ import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
@Mixin(KeyboardInput.class)
@SuppressWarnings("UnreachableCode")
public abstract class HookClientPlayerInputTick {
@Inject(method = "tick(ZF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/KeyboardInput;up:Z", ordinal = 0, shift = AFTER))
@Inject(
method = "tick",
at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/KeyboardInput;keyPresses:Lnet/minecraft/world/entity/player/Input;", ordinal = 0, shift = AFTER)
)
private void afterInputTick(final CallbackInfo info) {
@SuppressWarnings("ConstantConditions")
final Input input = (Input)(Object)this;
final LocalPlayer player = Minecraft.getInstance().player;
if (player != null) {
PlayerTicker.get(player).afterInputAssignsPressingForward(input);
PlayerTicker.get(player).afterKeyboardInputAssigned(player);
}
}
}

View File

@ -25,7 +25,7 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayer {
PlayerTicker.get(player).atHead(player);
}
@Inject(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/Input;tick(ZF)V", ordinal = 0, shift = AFTER))
@Inject(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/ClientInput;tick()V", ordinal = 0, shift = AFTER))
private void afterInputTick(final CallbackInfo info) {
@SuppressWarnings("ConstantConditions")
final LocalPlayer player = (LocalPlayer)(Object)this;

View File

@ -25,10 +25,9 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
@Inject(method = "addOptions", at = @At("RETURN"))
public void afterAddOptions(final CallbackInfo ci) {
@SuppressWarnings("ConstantConditions")
final ControlsScreen screen = (ControlsScreen)(Object)this;
if (list != null) {
@SuppressWarnings("ConstantConditions")
final ControlsScreen screen = (ControlsScreen)(Object)this;
final MutableComponent buttonTitle = BetterControlsScreen.TITLE.plainCopy().append("...");
list.addSmall(List.of(Button.builder(buttonTitle, btn -> showOptionsScreen(screen)).build()));
}
@ -36,7 +35,6 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
@Unique
private static void showOptionsScreen(final ControlsScreen screen) {
final Minecraft mc = Minecraft.getInstance();
mc.setScreen(new BetterControlsScreen(mc, screen));
Minecraft.getInstance().setScreen(new BetterControlsScreen(screen));
}
}

View File

@ -14,8 +14,9 @@ import net.minecraft.client.Camera;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.ClientInput;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.player.Input;
import java.lang.ref.WeakReference;
import java.util.function.BooleanSupplier;
@ -148,19 +149,25 @@ public final class PlayerTicker {
toggleSneak.tick();
}
public void afterInputAssignsPressingForward(final Input input) {
if (MINECRAFT.screen == null) {
//noinspection NonShortCircuitBooleanExpression
input.up |= toggleWalkForward.tick();
public void afterKeyboardInputAssigned(final LocalPlayer player) {
if (MINECRAFT.screen == null && toggleWalkForward.tick()) {
final ClientInput input = player.input;
input.keyPresses = new Input(
true,
input.keyPresses.backward(),
input.keyPresses.left(),
input.keyPresses.right(),
input.keyPresses.jump(),
input.keyPresses.shift(),
input.keyPresses.sprint()
);
}
}
public void afterInputTick(final LocalPlayer player) {
final Input input = player.input;
if (MINECRAFT.screen == null && !player.getAbilities().flying) {
//noinspection NonShortCircuitBooleanExpression
input.jumping |= toggleJump.tick();
if (MINECRAFT.screen == null && !player.getAbilities().flying && toggleJump.tick()) {
player.input.makeJump();
}
if (cfg().resumeSprintingAfterHittingObstacle) {
@ -223,13 +230,13 @@ public final class PlayerTicker {
}
if (FlightHelper.isFlyingCreativeOrSpectator(player) && cfg().disableFlightInertia) {
final Input input = player.input;
final ClientInput input = player.input;
if (input.forwardImpulse == 0F && input.leftImpulse == 0F) {
player.setDeltaMovement(player.getDeltaMovement().multiply(0.0, 1.0, 0.0));
}
if (!input.jumping && !input.shiftKeyDown) {
if (!input.keyPresses.jump() && !input.keyPresses.shift()) {
player.setDeltaMovement(player.getDeltaMovement().multiply(1.0, 0.0, 1.0));
}
}
@ -276,7 +283,7 @@ public final class PlayerTicker {
}
if (cfg().keyOpenMenu.isDown()) {
MINECRAFT.setScreen(new BetterControlsScreen(MINECRAFT, null));
MINECRAFT.setScreen(new BetterControlsScreen(null));
}
}