Skip to content

Commit

Permalink
Fix mouse not unlocking when option is turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed May 5, 2024
1 parent cccee19 commit 0b3a393
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public void updateContent() {
addSimpleIcoText(Ico.LIME_DYE, "Farming XP/h: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) FarmingHud.farmingXpPerHour()));

Entity cameraEntity = client.getCameraEntity();
String yaw = cameraEntity == null ? "No Camera Entity" : String.format("%.3f", MathHelper.wrapDegrees(cameraEntity.getYaw()));
String pitch = cameraEntity == null ? "No Camera Entity" : String.format("%.3f", MathHelper.wrapDegrees(cameraEntity.getPitch()));
addComponent(new PlainTextComponent(Text.literal("Yaw: " + yaw).formatted(Formatting.YELLOW)));
addComponent(new PlainTextComponent(Text.literal("Pitch: " + pitch).formatted(Formatting.YELLOW)));
String yaw = cameraEntity == null ? "No Camera Entity" : String.format("%.2f", MathHelper.wrapDegrees(cameraEntity.getYaw()));
String pitch = cameraEntity == null ? "No Camera Entity" : String.format("%.2f", MathHelper.wrapDegrees(cameraEntity.getPitch()));
addComponent(new PlainTextComponent(Text.literal("Yaw: " + yaw).formatted(Formatting.GOLD)));
addComponent(new PlainTextComponent(Text.literal("Pitch: " + pitch).formatted(Formatting.GOLD)));
if (LowerSensitivity.isSensitivityLowered()) {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.garden.hud.mouseLocked").formatted(Formatting.ITALIC)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@
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 (Utils.getLocation() != Location.GARDEN || MinecraftClient.getInstance().player == null || !SkyblockerConfigManager.get().locations.garden.lockMouseTool) {
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);

}
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;
}

Expand Down

0 comments on commit 0b3a393

Please sign in to comment.