diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index e334ef860a..64f1bf37d5 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -23,6 +23,7 @@ import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; import de.hysky.skyblocker.skyblock.end.TheEnd; import de.hysky.skyblocker.skyblock.garden.FarmingHud; +import de.hysky.skyblocker.skyblock.garden.LowerSensitivity; import de.hysky.skyblocker.skyblock.garden.VisitorHelper; import de.hysky.skyblocker.skyblock.item.*; import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview; @@ -113,6 +114,7 @@ public void onInitializeClient() { DwarvenHud.init(); CrystalsHud.init(); FarmingHud.init(); + LowerSensitivity.init(); CrystalsLocationsManager.init(); ChatMessageListener.init(); Shortcuts.init(); diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index a3e710c1ba..6da1f46549 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -1094,6 +1094,12 @@ public static class Garden { @SerialEntry public boolean visitorHelper = true; + + @SerialEntry + public boolean lockMouseTool = false; + + @SerialEntry + public boolean lockMouseGroundOnly = false; } public static class FarmingHud { diff --git a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java index 86ed3f6c15..67512b7883 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java @@ -166,6 +166,20 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig newValue -> config.locations.garden.visitorHelper = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.lockMouseTool")) + .binding(defaults.locations.garden.lockMouseTool, + () -> config.locations.garden.lockMouseTool, + newValue -> config.locations.garden.lockMouseTool = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.lockMouseGround")) + .binding(defaults.locations.garden.lockMouseGroundOnly, + () -> config.locations.garden.lockMouseGroundOnly, + newValue -> config.locations.garden.lockMouseGroundOnly = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) .build(); } diff --git a/src/main/java/de/hysky/skyblocker/mixin/MouseMixin.java b/src/main/java/de/hysky/skyblocker/mixin/MouseMixin.java new file mode 100644 index 0000000000..33c3f48749 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/mixin/MouseMixin.java @@ -0,0 +1,19 @@ +package de.hysky.skyblocker.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import de.hysky.skyblocker.skyblock.garden.LowerSensitivity; +import net.minecraft.client.Mouse; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(Mouse.class) +public class MouseMixin { + + @ModifyExpressionValue(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;", ordinal = 0)) + public Object skyblocker$gardenMouseLock(Object original) { + if (LowerSensitivity.isSensitivityLowered()) + return -1 / 3d; + else return original; + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java index 72efb207ff..febbe825a7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java @@ -18,7 +18,7 @@ public class FarmingHudWidget extends Widget { private static final MutableText TITLE = Text.literal("Farming").formatted(Formatting.YELLOW, Formatting.BOLD); - private static final Map FARMING_TOOLS = Map.ofEntries( + public static final Map FARMING_TOOLS = Map.ofEntries( Map.entry("THEORETICAL_HOE_WHEAT_1", Ico.WHEAT), Map.entry("THEORETICAL_HOE_WHEAT_2", Ico.WHEAT), Map.entry("THEORETICAL_HOE_WHEAT_3", Ico.WHEAT), @@ -65,5 +65,8 @@ public void updateContent() { double pitch = cameraEntity == null ? 0.0d : cameraEntity.getPitch(); addComponent(new PlainTextComponent(Text.literal("Yaw: " + String.format("%.3f", MathHelper.wrapDegrees(yaw))).formatted(Formatting.YELLOW))); addComponent(new PlainTextComponent(Text.literal("Pitch: " + String.format("%.3f", MathHelper.wrapDegrees(pitch))).formatted(Formatting.YELLOW))); + if (LowerSensitivity.isSensitivityLowered()) { + addComponent(new PlainTextComponent(Text.translatable("skyblocker.garden.hud.mouseLocked").formatted(Formatting.ITALIC))); + } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/LowerSensitivity.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/LowerSensitivity.java new file mode 100644 index 0000000000..edea50deb5 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/LowerSensitivity.java @@ -0,0 +1,40 @@ +package de.hysky.skyblocker.skyblock.garden; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.Location; +import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.ItemStack; + +public class LowerSensitivity { + + private static boolean sensitivityLowered = false; + + public static void init() { + ClientTickEvents.END_WORLD_TICK.register(world -> { + if (!Utils.isOnSkyblock() || Utils.getLocation() != Location.GARDEN || MinecraftClient.getInstance().player == null) { + if (sensitivityLowered) lowerSensitivity(false); + return; + } + if (SkyblockerConfigManager.get().locations.garden.lockMouseTool) { + ItemStack mainHandStack = MinecraftClient.getInstance().player.getMainHandStack(); + String itemId = ItemUtils.getItemId(mainHandStack); + boolean shouldLockMouse = FarmingHudWidget.FARMING_TOOLS.containsKey(itemId) && (!SkyblockerConfigManager.get().locations.garden.lockMouseGroundOnly || MinecraftClient.getInstance().player.isOnGround()); + if (shouldLockMouse && !sensitivityLowered) lowerSensitivity(true); + else if (!shouldLockMouse && sensitivityLowered) lowerSensitivity(false); + + } + }); + } + + public static void lowerSensitivity(boolean lowerSensitivity) { + if (sensitivityLowered == lowerSensitivity) return; + sensitivityLowered = lowerSensitivity; + } + + public static boolean isSensitivityLowered() { + return sensitivityLowered; + } +} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index ff0ffa11ee..feb635fa57 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -206,6 +206,8 @@ "text.autoconfig.skyblocker.option.locations.garden.farmingHud.config": "Farming HUD Config...", "text.autoconfig.skyblocker.option.locations.garden.dicerTitlePrevent": "Enable Dicer Title Prevent", "text.autoconfig.skyblocker.option.locations.garden.visitorHelper": "Visitor helper", + "text.autoconfig.skyblocker.option.locations.garden.lockMouseTool": "Lock camera when holding a farming tool", + "text.autoconfig.skyblocker.option.locations.garden.lockMouseGround": "Only lock camera when on the ground", "text.autoconfig.skyblocker.option.locations.dungeons": "Dungeons", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints": "Dungeon Secret Waypoints", "text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableRoomMatching": "Enable Room Matching", @@ -495,6 +497,8 @@ "skyblocker.end.hud.protectorLocations.rightFront": "Right Front", "skyblocker.end.hud.protectorLocations.rightBack": "Right Back", + "skyblocker.garden.hud.mouseLocked": "Mouse locked.", + "skyblocker.fishing.reelNow": "Reel in now!", "skyblocker.rift.healNow": "Heal now!", "skyblocker.rift.iceNow": "Ice now!", diff --git a/src/main/resources/skyblocker.mixins.json b/src/main/resources/skyblocker.mixins.json index cc08ced8a3..11002372e0 100644 --- a/src/main/resources/skyblocker.mixins.json +++ b/src/main/resources/skyblocker.mixins.json @@ -25,6 +25,7 @@ "LeverBlockMixin", "LivingEntityRendererMixin", "MinecraftClientMixin", + "MouseMixin", "PlayerInventoryMixin", "PlayerListHudMixin", "PlayerSkinProviderMixin",