Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic garden mouse locking feature #607

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,6 +114,7 @@ public void onInitializeClient() {
DwarvenHud.init();
CrystalsHud.init();
FarmingHud.init();
LowerSensitivity.init();
CrystalsLocationsManager.init();
ChatMessageListener.init();
Shortcuts.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.locations.garden.visitorHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>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.<Boolean>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();
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
@@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ItemStack> FARMING_TOOLS = Map.ofEntries(
public static final Map<String, ItemStack> 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),
Expand Down Expand Up @@ -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)));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"LeverBlockMixin",
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"MouseMixin",
"PlayerInventoryMixin",
"PlayerListHudMixin",
"PlayerSkinProviderMixin",
Expand Down