diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index d86dc22..c31b01a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -40,6 +40,7 @@ public class CommandManager { SelfCareCommand.register(this.dispatcher); AutoSkinCommand.register(this.dispatcher); ReloadConfigCommand.register(this.dispatcher); + LoopCrouchCommand.register(this.dispatcher); } public void executeCommand (String command) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/LoopCrouchCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/LoopCrouchCommand.java new file mode 100644 index 0000000..d13f441 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/LoopCrouchCommand.java @@ -0,0 +1,37 @@ +package land.chipmunk.chipmunkmod.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import land.chipmunk.chipmunkmod.modules.LoopCrouch; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.text.Text; + +import static com.mojang.brigadier.arguments.BoolArgumentType.bool; +import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; + +public class LoopCrouchCommand { + public static void register (CommandDispatcher dispatcher) { + dispatcher.register( + literal("loopcrouch") + .then( + argument("enabled", bool()) + .executes(LoopCrouchCommand::run) + ) + ); + } + + public static int run (CommandContext context) { + final FabricClientCommandSource source = context.getSource(); + + final boolean enabled = getBool(context, "enabled"); + + LoopCrouch.INSTANCE.enabled(enabled); + + source.sendFeedback(Text.literal("Loop crouch is now " + (enabled ? "enabled" : "disabled"))); + + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index fd0c24f..79e984c 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -1,8 +1,6 @@ package land.chipmunk.chipmunkmod.mixin; -import land.chipmunk.chipmunkmod.modules.Players; -import land.chipmunk.chipmunkmod.modules.RainbowName; -import land.chipmunk.chipmunkmod.modules.SongPlayer; +import land.chipmunk.chipmunkmod.modules.*; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -15,7 +13,6 @@ import net.minecraft.registry.CombinedDynamicRegistries; import net.minecraft.client.network.ClientDynamicRegistryType; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; -import land.chipmunk.chipmunkmod.modules.SelfCare; @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { @@ -28,12 +25,13 @@ public class ClientPlayNetworkHandlerMixin { CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess); SelfCare.INSTANCE.init(); + LoopCrouch.INSTANCE.init(); SongPlayer.INSTANCE.coreReady(); RainbowName.INSTANCE.init(); } @Inject(method = "onGameJoin", at = @At("HEAD")) - private void onGameJoiHead (GameJoinS2CPacket packet, CallbackInfo ci) { + private void onGameJoinHead (GameJoinS2CPacket packet, CallbackInfo ci) { Players.INSTANCE.init(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/KeyboardInputMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/KeyboardInputMixin.java new file mode 100644 index 0000000..a0bb60f --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/KeyboardInputMixin.java @@ -0,0 +1,54 @@ +package land.chipmunk.chipmunkmod.mixin; + +import land.chipmunk.chipmunkmod.modules.LoopCrouch; +import net.minecraft.client.input.Input; +import net.minecraft.client.input.KeyboardInput; +import net.minecraft.client.option.GameOptions; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(KeyboardInput.class) +public class KeyboardInputMixin extends Input { + @Final + @Mutable + @Shadow + private final GameOptions settings; + + public KeyboardInputMixin (GameOptions settings) { + this.settings = settings; + } + + @Inject(method = "tick", at = @At("TAIL")) + private void tick (boolean slowDown, float f, CallbackInfo ci) { + this.pressingForward = this.settings.forwardKey.isPressed(); + this.pressingBack = this.settings.backKey.isPressed(); + this.pressingLeft = this.settings.leftKey.isPressed(); + this.pressingRight = this.settings.rightKey.isPressed(); + this.movementForward = getMovementMultiplier(this.pressingForward, this.pressingBack); + this.movementSideways = getMovementMultiplier(this.pressingLeft, this.pressingRight); + this.jumping = this.settings.jumpKey.isPressed(); + + // ohio code + this.sneaking = LoopCrouch.INSTANCE.enabled() ? + !LoopCrouch.INSTANCE.sneaking() : + this.settings.sneakKey.isPressed(); + LoopCrouch.INSTANCE.sneaking(!LoopCrouch.INSTANCE.sneaking()); + + if (slowDown) { + this.movementSideways *= f; + this.movementForward *= f; + } + } + + private float getMovementMultiplier(boolean positive, boolean negative) { + if (positive == negative) { + return 0.0f; + } + return positive ? 1.0f : -1.0f; + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/LoopCrouch.java b/src/main/java/land/chipmunk/chipmunkmod/modules/LoopCrouch.java new file mode 100644 index 0000000..58ec004 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/LoopCrouch.java @@ -0,0 +1,17 @@ +package land.chipmunk.chipmunkmod.modules; + +import lombok.Getter; +import lombok.Setter; + +public class LoopCrouch { + public static final LoopCrouch INSTANCE = new LoopCrouch(); + + @Getter @Setter private boolean enabled = false; + + @Getter @Setter private boolean sneaking = false; + + public LoopCrouch () { + } + + public void init () {} +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 5b19f67..b1d9708 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -15,7 +15,8 @@ "LightmapTextureManagerMixin", "DecoderHandlerMixin", "StringHelperMixin", - "NbtIoMixin" + "NbtIoMixin", + "KeyboardInputMixin" ], "injectors": { "defaultRequire": 1