mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-05-02 11:34:03 +02:00
Update for Minecraft 1.21.4
This commit is contained in:
parent
464bd3bcb6
commit
2cb16b1b74
Fabric/src/main/java/chylex/bettercontrols/compatibility
NeoForge/src/main/java/chylex/bettercontrols
src/main/java/chylex/bettercontrols
@ -3,11 +3,10 @@ package chylex.bettercontrols.compatibility;
|
|||||||
import chylex.bettercontrols.gui.BetterControlsScreen;
|
import chylex.bettercontrols.gui.BetterControlsScreen;
|
||||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
|
|
||||||
public class ModMenuSupport implements ModMenuApi {
|
public class ModMenuSupport implements ModMenuApi {
|
||||||
@Override
|
@Override
|
||||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
return parentScreen -> new BetterControlsScreen(Minecraft.getInstance(), parentScreen);
|
return BetterControlsScreen::new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,26 @@ package chylex.bettercontrols;
|
|||||||
|
|
||||||
import chylex.bettercontrols.config.BetterControlsConfig;
|
import chylex.bettercontrols.config.BetterControlsConfig;
|
||||||
import chylex.bettercontrols.gui.BetterControlsScreen;
|
import chylex.bettercontrols.gui.BetterControlsScreen;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.ModLoadingContext;
|
import net.neoforged.fml.ModLoadingContext;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.loading.FMLEnvironment;
|
import net.neoforged.fml.loading.FMLEnvironment;
|
||||||
import net.neoforged.fml.loading.FMLPaths;
|
import net.neoforged.fml.loading.FMLPaths;
|
||||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@Mod("bettercontrols")
|
@Mod("bettercontrols")
|
||||||
public final class BetterControlsMod {
|
public final class BetterControlsMod {
|
||||||
public BetterControlsMod() {
|
public BetterControlsMod() {
|
||||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||||
BetterControlsCommon.setConfig(BetterControlsConfig.load(FMLPaths.CONFIGDIR.get().resolve("BetterControls.json")));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,8 +206,8 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
|
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
|
||||||
|
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
public BetterControlsScreen(final Minecraft mc, @Nullable final Screen parentScreen) {
|
public BetterControlsScreen(@Nullable final Screen parentScreen) {
|
||||||
super(parentScreen, mc.options, TITLE);
|
super(parentScreen, Minecraft.getInstance().options, TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,13 +70,13 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getScrollbarPosition() {
|
protected int scrollBarX() {
|
||||||
return (width + ROW_WIDTH) / 2 + 4;
|
return (width + ROW_WIDTH) / 2 + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled(final double x, final double y, final double xAmount, final double yAmount) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,23 +4,19 @@ import chylex.bettercontrols.player.PlayerTicker;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.world.entity.player.Abilities;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.Slice;
|
|
||||||
|
|
||||||
@Mixin(AbstractClientPlayer.class)
|
@Mixin(AbstractClientPlayer.class)
|
||||||
public abstract class HookClientPlayerFOV {
|
public abstract class HookClientPlayerFOV {
|
||||||
@Redirect(
|
@Redirect(
|
||||||
method = "getFieldOfViewModifier",
|
method = "getFieldOfViewModifier",
|
||||||
at = @At(value = "INVOKE", target = "Ljava/lang/Float;isNaN(F)Z"),
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getWalkingSpeed()F")
|
||||||
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")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
private boolean resetFOV(final float movementSpeed) {
|
private float overrideWalkingSpeed(final Abilities abilities) {
|
||||||
final LocalPlayer player = Minecraft.getInstance().player;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package chylex.bettercontrols.mixin;
|
|||||||
|
|
||||||
import chylex.bettercontrols.player.PlayerTicker;
|
import chylex.bettercontrols.player.PlayerTicker;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.Input;
|
|
||||||
import net.minecraft.client.player.KeyboardInput;
|
import net.minecraft.client.player.KeyboardInput;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@ -14,14 +13,15 @@ import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
|
|||||||
@Mixin(KeyboardInput.class)
|
@Mixin(KeyboardInput.class)
|
||||||
@SuppressWarnings("UnreachableCode")
|
@SuppressWarnings("UnreachableCode")
|
||||||
public abstract class HookClientPlayerInputTick {
|
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) {
|
private void afterInputTick(final CallbackInfo info) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
final Input input = (Input)(Object)this;
|
|
||||||
final LocalPlayer player = Minecraft.getInstance().player;
|
final LocalPlayer player = Minecraft.getInstance().player;
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerTicker.get(player).afterInputAssignsPressingForward(input);
|
PlayerTicker.get(player).afterKeyboardInputAssigned(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayer {
|
|||||||
PlayerTicker.get(player).atHead(player);
|
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) {
|
private void afterInputTick(final CallbackInfo info) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
final LocalPlayer player = (LocalPlayer)(Object)this;
|
final LocalPlayer player = (LocalPlayer)(Object)this;
|
||||||
|
@ -25,10 +25,9 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
|
|||||||
|
|
||||||
@Inject(method = "addOptions", at = @At("RETURN"))
|
@Inject(method = "addOptions", at = @At("RETURN"))
|
||||||
public void afterAddOptions(final CallbackInfo ci) {
|
public void afterAddOptions(final CallbackInfo ci) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
final ControlsScreen screen = (ControlsScreen)(Object)this;
|
|
||||||
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
final ControlsScreen screen = (ControlsScreen)(Object)this;
|
||||||
final MutableComponent buttonTitle = BetterControlsScreen.TITLE.plainCopy().append("...");
|
final MutableComponent buttonTitle = BetterControlsScreen.TITLE.plainCopy().append("...");
|
||||||
list.addSmall(List.of(Button.builder(buttonTitle, btn -> showOptionsScreen(screen)).build()));
|
list.addSmall(List.of(Button.builder(buttonTitle, btn -> showOptionsScreen(screen)).build()));
|
||||||
}
|
}
|
||||||
@ -36,7 +35,6 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
|
|||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private static void showOptionsScreen(final ControlsScreen screen) {
|
private static void showOptionsScreen(final ControlsScreen screen) {
|
||||||
final Minecraft mc = Minecraft.getInstance();
|
Minecraft.getInstance().setScreen(new BetterControlsScreen(screen));
|
||||||
mc.setScreen(new BetterControlsScreen(mc, screen));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,9 @@ import net.minecraft.client.Camera;
|
|||||||
import net.minecraft.client.KeyMapping;
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.Options;
|
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.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.world.entity.player.Input;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
@ -148,19 +149,25 @@ public final class PlayerTicker {
|
|||||||
toggleSneak.tick();
|
toggleSneak.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterInputAssignsPressingForward(final Input input) {
|
public void afterKeyboardInputAssigned(final LocalPlayer player) {
|
||||||
if (MINECRAFT.screen == null) {
|
if (MINECRAFT.screen == null && toggleWalkForward.tick()) {
|
||||||
//noinspection NonShortCircuitBooleanExpression
|
final ClientInput input = player.input;
|
||||||
input.up |= toggleWalkForward.tick();
|
|
||||||
|
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) {
|
public void afterInputTick(final LocalPlayer player) {
|
||||||
final Input input = player.input;
|
if (MINECRAFT.screen == null && !player.getAbilities().flying && toggleJump.tick()) {
|
||||||
|
player.input.makeJump();
|
||||||
if (MINECRAFT.screen == null && !player.getAbilities().flying) {
|
|
||||||
//noinspection NonShortCircuitBooleanExpression
|
|
||||||
input.jumping |= toggleJump.tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg().resumeSprintingAfterHittingObstacle) {
|
if (cfg().resumeSprintingAfterHittingObstacle) {
|
||||||
@ -223,13 +230,13 @@ public final class PlayerTicker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FlightHelper.isFlyingCreativeOrSpectator(player) && cfg().disableFlightInertia) {
|
if (FlightHelper.isFlyingCreativeOrSpectator(player) && cfg().disableFlightInertia) {
|
||||||
final Input input = player.input;
|
final ClientInput input = player.input;
|
||||||
|
|
||||||
if (input.forwardImpulse == 0F && input.leftImpulse == 0F) {
|
if (input.forwardImpulse == 0F && input.leftImpulse == 0F) {
|
||||||
player.setDeltaMovement(player.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
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));
|
player.setDeltaMovement(player.getDeltaMovement().multiply(1.0, 0.0, 1.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +283,7 @@ public final class PlayerTicker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cfg().keyOpenMenu.isDown()) {
|
if (cfg().keyOpenMenu.isDown()) {
|
||||||
MINECRAFT.setScreen(new BetterControlsScreen(MINECRAFT, null));
|
MINECRAFT.setScreen(new BetterControlsScreen(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user