From 4a43b965bb0b105eb5c614932f965449e930f56b Mon Sep 17 00:00:00 2001
From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Date: Sat, 9 Mar 2024 16:56:14 -0500
Subject: [PATCH 1/5] Refactor Hud Config Screens and fix dragging
---
.../de/hysky/skyblocker/SkyblockerMod.java | 6 +-
.../skyblocker/config/HudConfigScreen.java | 128 +++++++++++++-----
.../skyblocker/config/SkyblockerConfig.java | 24 +++-
.../categories/DwarvenMinesCategory.java | 7 -
.../config/categories/GeneralCategory.java | 8 ++
.../config/categories/LocationsCategory.java | 22 +--
.../skyblock/dwarven/CrystalsHud.java | 17 +--
.../dwarven/CrystalsHudConfigScreen.java | 65 +++------
.../skyblock/dwarven/DwarvenHud.java | 71 ++--------
.../dwarven/DwarvenHudConfigScreen.java | 75 ++++------
.../skyblock/end/EndHudConfigScreen.java | 29 ++--
.../hysky/skyblocker/skyblock/end/TheEnd.java | 2 +-
.../skyblock/garden/FarmingHud.java | 16 +++
.../garden/FarmingHudConfigScreen.java | 31 +++++
.../skyblock/tabhud/widget/EmptyWidget.java | 12 ++
.../skyblock/tabhud/widget/Widget.java | 27 +++-
.../tabhud/widget/hud/HudFarmingWidget.java | 22 +++
.../assets/skyblocker/lang/en_us.json | 7 +-
18 files changed, 323 insertions(+), 246 deletions(-)
create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java
create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
index 0bd3c8e33f..39e14e1ba8 100644
--- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
+++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
@@ -6,8 +6,8 @@
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.skyblock.*;
import de.hysky.skyblocker.skyblock.chat.ChatRuleAnnouncementScreen;
-import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra;
import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler;
+import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra;
import de.hysky.skyblocker.skyblock.dungeon.*;
import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen;
import de.hysky.skyblocker.skyblock.dungeon.puzzle.*;
@@ -20,6 +20,7 @@
import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud;
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.VisitorHelper;
import de.hysky.skyblocker.skyblock.item.*;
import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview;
@@ -105,8 +106,10 @@ public void onInitializeClient() {
BackpackPreview.init();
QuickNav.init();
ItemCooldowns.init();
+ TabHud.init();
DwarvenHud.init();
CrystalsHud.init();
+ FarmingHud.init();
CrystalsLocationsManager.init();
ChatMessageListener.init();
Shortcuts.init();
@@ -115,7 +118,6 @@ public void onInitializeClient() {
DiscordRPCManager.init();
LividColor.init();
FishingHelper.init();
- TabHud.init();
DungeonMap.init();
DungeonManager.init();
DungeonBlaze.init();
diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
index c33e2f54f9..6884af8358 100644
--- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
@@ -2,82 +2,142 @@
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.utils.render.RenderHelper;
-import it.unimi.dsi.fastutil.ints.IntIntImmutablePair;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
+import net.minecraft.util.math.MathHelper;
import java.awt.*;
+import java.util.List;
+/**
+ * A screen for configuring the positions of HUD widgets.
+ *
+ * This class takes care of rendering the widgets, dragging them, and resetting their positions.
+ * Create one subclass for each collection of HUD widgets that are displayed at the same time.
+ * (i.e. one for dwarven mines, one for the end, etc.) See an implementation for an example.
+ */
public abstract class HudConfigScreen extends Screen {
- private final Widget widget;
private final Screen parent;
+ private final List widgets;
- private int hudX = 0;
- private int hudY = 0;
- public HudConfigScreen(Text title, Widget widget, Screen parent) {
+ private Widget draggingWidget;
+ private double mouseClickRelativeX;
+ private double mouseClickRelativeY;
+
+ /**
+ * Creates a new HudConfigScreen with the passed title, parent, and widget
+ * @param title the title of the screen
+ * @param parent the parent screen
+ * @param widget the widget to configure
+ */
+ public HudConfigScreen(Text title, Screen parent, Widget widget) {
+ this(title, parent, List.of(widget));
+ }
+
+ /**
+ * Creates a new HudConfigScreen with the passed title, parent, and widgets
+ * @param title the title of the screen
+ * @param parent the parent screen
+ * @param widgets the widgets to configure
+ */
+ public HudConfigScreen(Text title, Screen parent, List widgets) {
super(title);
- this.widget = widget;
this.parent = parent;
-
- int[] posFromConfig = getPosFromConfig(SkyblockerConfigManager.get());
- hudX = posFromConfig[0];
- hudY = posFromConfig[1];
+ this.widgets = widgets;
+ resetPos();
}
@Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
+ public final void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
renderBackground(context, mouseX, mouseY, delta);
- renderWidget(context, hudX, hudY);
+ renderWidget(context, widgets);
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
}
+ /**
+ * Renders the widgets using the default {@link Widget#render(DrawContext, boolean)} method. Override to change the behavior.
+ * @param context the context to render in
+ * @param widgets the widgets to render
+ */
+ protected void renderWidget(DrawContext context, List widgets) {
+ for (Widget widget : widgets) {
+ widget.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ }
+ }
+
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- IntIntPair dims = getDimensions();
- if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && button == 0) {
- hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0);
- hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0);
+ public final boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+ if (button == 0 && draggingWidget != null) {
+ draggingWidget.setX((int) MathHelper.clamp(mouseX - mouseClickRelativeX, 0, this.width - draggingWidget.getWidth()));
+ draggingWidget.setY((int) MathHelper.clamp(mouseY - mouseClickRelativeY, 0, this.height - draggingWidget.getHeight()));
}
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (button == 1) {
- IntIntPair dims = getDimensions();
- hudX = this.width / 2 - dims.leftInt();
- hudY = this.height / 2 - dims.rightInt();
+ public final boolean mouseClicked(double mouseX, double mouseY, int button) {
+ if (button == 0) {
+ for (Widget widget : widgets) {
+ if (RenderHelper.pointIsInArea(mouseX, mouseY, widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight())) {
+ draggingWidget = widget;
+ mouseClickRelativeX = mouseX - widget.getX();
+ mouseClickRelativeY = mouseY - widget.getY();
+ break;
+ }
+ }
+ } else if (button == 1) {
+ resetPos();
}
return super.mouseClicked(mouseX, mouseY, button);
}
- abstract protected int[] getPosFromConfig(SkyblockerConfig config);
+ @Override
+ public final boolean mouseReleased(double mouseX, double mouseY, int button) {
+ draggingWidget = null;
+ return super.mouseReleased(mouseX, mouseY, button);
+ }
- protected IntIntPair getDimensions() {
- return new IntIntImmutablePair(widget.getHeight(), widget.getWidth());
+ /**
+ * Resets the positions of the widgets to the positions in the config. Override to change the behavior.
+ */
+ protected void resetPos() {
+ List configPositions = getConfigPos(SkyblockerConfigManager.get());
+ if (configPositions.size() != widgets.size()) {
+ throw new IllegalStateException("The number of positions (" + configPositions.size() + ") does not match the number of widgets (" + widgets.size() + ")");
+ }
+ for (int i = 0; i < widgets.size(); i++) {
+ Widget widget = widgets.get(i);
+ IntIntMutablePair configPos = configPositions.get(i);
+ widget.setX(configPos.leftInt());
+ widget.setY(configPos.rightInt());
+ }
}
+ /**
+ * Returns the positions of the widgets in the config
+ * @param config the config to get the positions from
+ * @return the positions of the widgets
+ */
+ protected abstract List getConfigPos(SkyblockerConfig config);
+
@Override
- public void close() {
+ public final void close() {
SkyblockerConfig skyblockerConfig = SkyblockerConfigManager.get();
- savePos(skyblockerConfig, hudX, hudY);
+ savePos(skyblockerConfig, widgets);
SkyblockerConfigManager.save();
client.setScreen(parent);
}
/**
- * This method should save the passed position to the config
+ * Saves the passed positions to the config.
*
* NOTE: The parent class will call {@link SkyblockerConfigManager#save()} right after this method
* @param configManager the config so you don't have to get it
- * @param x x
- * @param y y
+ * @param widgets the widgets to save
*/
- abstract protected void savePos(SkyblockerConfig configManager, int x, int y);
-
- abstract protected void renderWidget(DrawContext context, int x, int y);
+ protected abstract void savePos(SkyblockerConfig configManager, List widgets);
}
diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
index 9db212c14e..e60aa03b80 100644
--- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
+++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
@@ -266,6 +266,9 @@ public static class TabHudConf {
@SerialEntry
public int tabHudScale = 100;
+ @SerialEntry
+ public boolean enableHudBackground = true;
+
@SerialEntry
public boolean plainPlayerNames = false;
@@ -941,9 +944,6 @@ public static class DwarvenHud {
@SerialEntry
public DwarvenHudStyle style = DwarvenHudStyle.SIMPLE;
- @SerialEntry
- public boolean enableBackground = true;
-
@SerialEntry
public int x = 10;
@@ -1059,9 +1059,6 @@ public static class TheEnd {
@SerialEntry
public boolean hudEnabled = true;
- @SerialEntry
- public boolean enableBackground = true;
-
@SerialEntry
public boolean waypoint = true;
@@ -1086,6 +1083,9 @@ public static class Relics {
}
public static class Garden {
+ @SerialEntry
+ public FarmingHud farmingHud = new FarmingHud();
+
@SerialEntry
public boolean dicerTitlePrevent = true;
@@ -1093,6 +1093,17 @@ public static class Garden {
public boolean visitorHelper = true;
}
+ public static class FarmingHud {
+ @SerialEntry
+ public boolean enableHud = true;
+
+ @SerialEntry
+ public int x;
+
+ @SerialEntry
+ public int y;
+ }
+
public static class Slayer {
@SerialEntry
public EndermanSlayer endermanSlayer = new EndermanSlayer();
@@ -1196,6 +1207,7 @@ public static class Messages {
@SerialEntry
public ChatRuleConfig chatRuleConfig = new ChatRuleConfig();
}
+
public static class ChatRuleConfig {
@SerialEntry
public int announcementLength = 60;
diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
index 97b48bc41f..4ae0fc3595 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
@@ -76,13 +76,6 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.text(Text.translatable("text.skyblocker.open"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new DwarvenHudConfigScreen(screen)))
.build())
- .option(Option.createBuilder()
- .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground"))
- .binding(defaults.locations.dwarvenMines.dwarvenHud.enableBackground,
- () -> config.locations.dwarvenMines.dwarvenHud.enableBackground,
- newValue -> config.locations.dwarvenMines.dwarvenHud.enableBackground = newValue)
- .controller(ConfigUtils::createBooleanController)
- .build())
.build())
//crystal HUD
.group(OptionGroup.createBuilder()
diff --git a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
index afd688d8ba..23ce7bb63c 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
@@ -106,6 +106,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.tabHud.tabHudScale = newValue)
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(10, 200).step(1))
.build())
+ .option(Option.createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground"))
+ .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground.@Tooltip")))
+ .binding(defaults.general.tabHud.enableHudBackground,
+ () -> config.general.tabHud.enableHudBackground,
+ newValue -> config.general.tabHud.enableHudBackground = newValue)
+ .controller(ConfigUtils::createBooleanController)
+ .build())
.option(Option.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames.@Tooltip")))
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 d97513f85f..86ed3f6c15 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java
@@ -4,6 +4,7 @@
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.skyblock.end.EndHudConfigScreen;
import de.hysky.skyblocker.skyblock.end.TheEnd;
+import de.hysky.skyblocker.skyblock.garden.FarmingHudConfigScreen;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
import net.minecraft.client.MinecraftClient;
@@ -90,13 +91,6 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.locations.end.hudEnabled = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
- .option(Option.createBuilder()
- .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground")) // Reusing that string cuz sure
- .binding(defaults.locations.end.enableBackground,
- () -> config.locations.end.enableBackground,
- newValue -> config.locations.end.enableBackground = newValue)
- .controller(ConfigUtils::createBooleanController)
- .build())
.option(Option.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.waypoint"))
.binding(defaults.locations.end.waypoint,
@@ -146,6 +140,18 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden"))
.collapsed(false)
+ .option(Option.createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.farmingHud.enableHud"))
+ .binding(defaults.locations.garden.farmingHud.enableHud,
+ () -> config.locations.garden.farmingHud.enableHud,
+ newValue -> config.locations.garden.farmingHud.enableHud = newValue)
+ .controller(ConfigUtils::createBooleanController)
+ .build())
+ .option(ButtonOption.createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.farmingHud.config"))
+ .text(Text.translatable("text.skyblocker.open"))
+ .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new FarmingHudConfigScreen(screen)))
+ .build())
.option(Option.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.dicerTitlePrevent"))
.binding(defaults.locations.garden.dicerTitlePrevent,
@@ -154,7 +160,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.createBuilder()
- .name(Text.translatable("text.autoconfig.skyblocker.option.general.visitorHelper"))
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.visitorHelper"))
.binding(defaults.locations.garden.visitorHelper,
() -> config.locations.garden.visitorHelper,
newValue -> config.locations.garden.visitorHelper = newValue)
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
index 7b15c61ebc..f113561fee 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
@@ -4,7 +4,6 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
@@ -14,14 +13,13 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
+import org.joml.Vector2i;
+import org.joml.Vector2ic;
import java.awt.*;
import java.util.Arrays;
import java.util.Map;
-import org.joml.Vector2i;
-import org.joml.Vector2ic;
-
public class CrystalsHud {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png");
@@ -47,9 +45,8 @@ public static void init() {
});
}
- protected static IntIntPair getDimensionsForConfig() {
- int size = (int) (62 * SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling);
- return IntIntPair.of(size, size);
+ protected static int getDimensionsForConfig() {
+ return (int) (62 * SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling);
}
@@ -119,7 +116,7 @@ private static void render(DrawContext context, float tickDelta, int hudX, int h
}
/**
- * Converts an X and Z coordinate in the crystal hollow to a X and Y coordinate on the map.
+ * Converts an X and Z coordinate in the crystal hollow to an X and Y coordinate on the map.
*
* @param x the world X coordinate
* @param z the world Z coordinate
@@ -142,8 +139,8 @@ protected static Vector2ic transformLocation(double x, double z) {
* Based off code from {@link net.minecraft.client.render.MapRenderer}
*/
private static float yaw2Cardinal(float yaw) {
- yaw += + 180; //flip direction
- byte clipped = (byte) ((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0);
+ yaw += 180; //flip direction
+ byte clipped = (byte) ((yaw + (yaw < 0.0 ? -8.0 : 8.0)) * 16.0 / 360.0);
return (clipped * 360f) / 16f;
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
index b4e423e926..15e605b9e4 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
@@ -1,69 +1,44 @@
package de.hysky.skyblocker.skyblock.dwarven;
-import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.render.RenderHelper;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
+import de.hysky.skyblocker.config.HudConfigScreen;
+import de.hysky.skyblocker.config.SkyblockerConfig;
+import de.hysky.skyblocker.skyblock.tabhud.widget.EmptyWidget;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
-import java.awt.*;
+import java.util.List;
-public class CrystalsHudConfigScreen extends Screen {
-
- private int hudX = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x;
- private int hudY = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y;
- private final Screen parent;
+public class CrystalsHudConfigScreen extends HudConfigScreen {
+ private static final EmptyWidget WIDGET = new EmptyWidget();
protected CrystalsHudConfigScreen() {
this(null);
}
public CrystalsHudConfigScreen(Screen parent) {
- super(Text.of("Crystals HUD Config"));
- this.parent = parent;
- }
-
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
- super.render(context, mouseX, mouseY, delta);
- renderBackground(context, mouseX, mouseY, delta);
- renderHUDMap(context, hudX, hudY);
- context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
+ super(Text.of("Crystals HUD Config"), parent, WIDGET);
+ WIDGET.setDimensions(CrystalsHud.getDimensionsForConfig());
}
+ @SuppressWarnings("SuspiciousNameCombination")
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- IntIntPair dims = CrystalsHud.getDimensionsForConfig();
- if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && button == 0) {
- hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0);
- hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0);
- }
- return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
+ protected List getConfigPos(SkyblockerConfig config) {
+ return List.of(IntIntMutablePair.of(config.locations.dwarvenMines.crystalsHud.x, config.locations.dwarvenMines.crystalsHud.y));
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (button == 1) {
- IntIntPair dims = CrystalsHud.getDimensionsForConfig();
- hudX = this.width / 2 - dims.leftInt();
- hudY = this.height / 2 - dims.rightInt();
- }
- return super.mouseClicked(mouseX, mouseY, button);
+ protected void renderWidget(DrawContext context, List widgets) {
+ int size = CrystalsHud.getDimensionsForConfig();
+ WIDGET.setDimensions(size);
+ context.drawTexture(CrystalsHud.MAP_TEXTURE, WIDGET.getX(), WIDGET.getY(), 0, 0, size, size, size, size);
}
- private void renderHUDMap(DrawContext context, int x, int y) {
- float scaling = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling;
- int size = (int) (62 * scaling);
- context.drawTexture(CrystalsHud.MAP_TEXTURE, x, y, 0, 0, size, size, size, size);
- }
-
@Override
- public void close() {
- SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x = hudX;
- SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y = hudY;
- SkyblockerConfigManager.save();
-
- client.setScreen(parent);
+ protected void savePos(SkyblockerConfig configManager, List widgets) {
+ configManager.locations.dwarvenMines.crystalsHud.x = widgets.get(0).getX();
+ configManager.locations.dwarvenMines.crystalsHud.y = widgets.get(0).getY();
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
index 608873c014..8eb159355b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
@@ -6,8 +6,6 @@
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
-import it.unimi.dsi.fastutil.Pair;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
@@ -56,7 +54,7 @@ public static void init() {
.executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new))))));
HudRenderCallback.EVENT.register((context, tickDelta) -> {
- if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
+ if ((!SkyblockerConfigManager.get().general.tabHud.enableHudBackground && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
|| client.options.playerListKey.isPressed()
|| client.player == null
|| (!Utils.isInDwarvenMines() && !Utils.isInCrystalHollows())) {
@@ -72,52 +70,11 @@ public static void init() {
});
}
- /**
- * Gets the dimensions (width, height) for the commissions hud and the powder hud
- * @param commissions what commissions to get the dimensions for
- * @return a {@link Pair} of {@link IntIntPair} with the first pair being for the commissions hud and the second pair being for the powder hud
- */
- public static Pair getDimForConfig(List commissions) {
- return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
- case SIMPLE -> {
- HudCommsWidget.INSTANCE_CFG.updateData(commissions, false);
- yield Pair.of(
- IntIntPair.of(
- HudCommsWidget.INSTANCE_CFG.getWidth(),
- HudCommsWidget.INSTANCE_CFG.getHeight()),
- IntIntPair.of(
- HudPowderWidget.INSTANCE_CFG.getWidth(),
- HudPowderWidget.INSTANCE_CFG.getHeight())
- );
- }
- case FANCY -> {
- HudCommsWidget.INSTANCE_CFG.updateData(commissions, true);
- yield Pair.of(
- IntIntPair.of(
- HudCommsWidget.INSTANCE_CFG.getWidth(),
- HudCommsWidget.INSTANCE_CFG.getHeight()),
- IntIntPair.of(
- HudPowderWidget.INSTANCE_CFG.getWidth(),
- HudPowderWidget.INSTANCE_CFG.getHeight())
- );
- }
- default -> Pair.of(
- IntIntPair.of(
- 200,
- 20 * commissions.size()),
- IntIntPair.of(
- 200,
- 40)
- );
- };
- }
-
public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) {
-
switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
- case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions);
- case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions);
- case CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions);
+ case SIMPLE -> renderSimple(hcw, hpw, context, comHudX, comHudY, powderHudX, powderHudY, commissions);
+ case FANCY -> renderFancy(hcw, hpw, context, comHudX, comHudY, powderHudX, powderHudY, commissions);
+ case CLASSIC -> renderClassic(context, comHudX, comHudY, powderHudX, powderHudY, commissions);
}
}
@@ -131,11 +88,11 @@ public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext c
* @param commissions the commissions to render to the commissions hud
*/
public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) {
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000);
context.fill(powderHudX, powderHudY, powderHudX + 200, powderHudY + 40, 0x64000000);
}
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
int y = 0;
for (Commission commission : commissions) {
float percentage;
@@ -167,43 +124,41 @@ public static void renderClassic(DrawContext context, int comHudX, int comHudY,
}
public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) {
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
hcw.updateData(commissions, false);
hcw.update();
hcw.setX(comHudX);
hcw.setY(comHudY);
- hcw.render(context,
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
+ hcw.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
}
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) {
hpw.update();
hpw.setX(powderHudX);
hpw.setY(powderHudY);
- hpw.render(context,
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
+ hpw.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
}
}
public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) {
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
hcw.updateData(commissions, true);
hcw.update();
hcw.setX(comHudX);
hcw.setY(comHudY);
hcw.render(context,
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
+ SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
}
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) {
hpw.update();
hpw.setX(powderHudX);
hpw.setY(powderHudY);
hpw.render(context,
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
+ SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
}
}
public static void update() {
- if (client.player == null || client.getNetworkHandler() == null || (!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
+ if (client.player == null || client.getNetworkHandler() == null || (!SkyblockerConfigManager.get().general.tabHud.enableHudBackground && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
|| (!Utils.isInCrystalHollows() && !Utils.isInDwarvenMines()))
return;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java
index d5dc19f240..79a139f9d6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java
@@ -1,80 +1,55 @@
package de.hysky.skyblocker.skyblock.dwarven;
+import de.hysky.skyblocker.config.HudConfigScreen;
+import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud.Commission;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget;
-import de.hysky.skyblocker.utils.render.RenderHelper;
-import it.unimi.dsi.fastutil.Pair;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
-import java.awt.*;
import java.util.List;
-public class DwarvenHudConfigScreen extends Screen {
-
+public class DwarvenHudConfigScreen extends HudConfigScreen {
private static final List CFG_COMMS = List.of(new Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%"));
- private int commissionsHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x;
- private int commissionsHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y;
-
- private int powderHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX;
- private int powderHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY;
- private final Screen parent;
protected DwarvenHudConfigScreen() {
this(null);
}
public DwarvenHudConfigScreen(Screen parent) {
- super(Text.of("Dwarven HUD Config"));
- this.parent = parent;
- }
-
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
- super.render(context, mouseX, mouseY, delta);
- renderBackground(context, mouseX, mouseY, delta);
- DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY, powderHudX, powderHudY, CFG_COMMS);
- context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
+ super(Text.literal("Dwarven HUD Config"), parent, List.of(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG));
+ if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style == SkyblockerConfig.DwarvenHudStyle.CLASSIC) {
+ HudCommsWidget.INSTANCE_CFG.setWidth(200);
+ HudCommsWidget.INSTANCE_CFG.setHeight(20 * CFG_COMMS.size());
+ HudPowderWidget.INSTANCE_CFG.setWidth(200);
+ HudPowderWidget.INSTANCE_CFG.setHeight(40);
+ }
}
+ @SuppressWarnings("SuspiciousNameCombination")
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- Pair dims = DwarvenHud.getDimForConfig(CFG_COMMS);
- if (RenderHelper.pointIsInArea(mouseX, mouseY, commissionsHudX, commissionsHudY, commissionsHudX + 200, commissionsHudY + 40) && button == 0) {
- commissionsHudX = (int) Math.max(Math.min(mouseX - (double) dims.first().leftInt() / 2, this.width - dims.first().leftInt()), 0);
- commissionsHudY = (int) Math.max(Math.min(mouseY - (double) dims.first().rightInt() / 2, this.height - dims.first().rightInt()), 0);
- }
- if (RenderHelper.pointIsInArea(mouseX, mouseY, powderHudX, powderHudY, powderHudX + 200, powderHudY + 40) && button == 0) {
- powderHudX = (int) Math.max(Math.min(mouseX - (double) dims.second().leftInt() / 2, this.width - dims.second().leftInt()), 0);
- powderHudY = (int) Math.max(Math.min(mouseY - (double) dims.second().rightInt() / 2, this.height - dims.second().rightInt()), 0);
- }
- return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
+ protected List getConfigPos(SkyblockerConfig config) {
+ return List.of(
+ IntIntMutablePair.of(config.locations.dwarvenMines.dwarvenHud.x, config.locations.dwarvenMines.dwarvenHud.y),
+ IntIntMutablePair.of(config.locations.dwarvenMines.dwarvenHud.powderX, config.locations.dwarvenMines.dwarvenHud.powderY)
+ );
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (button == 1) {
- Pair dims = DwarvenHud.getDimForConfig(CFG_COMMS);
- commissionsHudX = this.width / 2 - dims.left().leftInt();
- commissionsHudY = this.height / 2 - dims.left().rightInt();
- powderHudX = this.width / 2 - dims.right().leftInt();
- powderHudY = this.height / 2 - dims.right().rightInt() + dims.left().rightInt(); //add this to make it bellow the other widget
- }
- return super.mouseClicked(mouseX, mouseY, button);
+ protected void renderWidget(DrawContext context, List widgets) {
+ DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, widgets.get(0).getX(), widgets.get(0).getY(), widgets.get(1).getX(), widgets.get(1).getY(), CFG_COMMS);
}
@Override
- public void close() {
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x = commissionsHudX;
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y = commissionsHudY;
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX = powderHudX;
- SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY = powderHudY;
- SkyblockerConfigManager.save();
-
- client.setScreen(parent);
+ protected void savePos(SkyblockerConfig configManager, List widgets) {
+ configManager.locations.dwarvenMines.dwarvenHud.x = widgets.get(0).getX();
+ configManager.locations.dwarvenMines.dwarvenHud.y = widgets.get(0).getY();
+ configManager.locations.dwarvenMines.dwarvenHud.powderX = widgets.get(1).getX();
+ configManager.locations.dwarvenMines.dwarvenHud.powderY = widgets.get(1).getY();
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java
index 2502afd7af..659fc79f6d 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java
@@ -2,34 +2,27 @@
import de.hysky.skyblocker.config.HudConfigScreen;
import de.hysky.skyblocker.config.SkyblockerConfig;
-import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import net.minecraft.client.gui.DrawContext;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
+import java.util.List;
+
public class EndHudConfigScreen extends HudConfigScreen {
public EndHudConfigScreen(Screen parent) {
- super(Text.literal("End HUD Config"), EndHudWidget.INSTANCE, parent);
- }
-
- @Override
- protected int[] getPosFromConfig(SkyblockerConfig config) {
- return new int[]{
- config.locations.end.x,
- config.locations.end.y,
- };
+ super(Text.literal("End HUD Config"), parent, EndHudWidget.INSTANCE);
}
+ @SuppressWarnings("SuspiciousNameCombination")
@Override
- protected void savePos(SkyblockerConfig configManager, int x, int y) {
- configManager.locations.end.x = x;
- configManager.locations.end.y = y;
+ protected List getConfigPos(SkyblockerConfig config) {
+ return List.of(IntIntMutablePair.of(config.locations.end.x, config.locations.end.y));
}
@Override
- protected void renderWidget(DrawContext context, int x, int y) {
- EndHudWidget.INSTANCE.setX(x);
- EndHudWidget.INSTANCE.setY(y);
- EndHudWidget.INSTANCE.render(context, SkyblockerConfigManager.get().locations.end.enableBackground);
+ protected void savePos(SkyblockerConfig configManager, List widgets) {
+ configManager.locations.end.x = widgets.get(0).getX();
+ configManager.locations.end.y = widgets.get(0).getY();
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java b/src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java
index 1db277694c..10672bde2d 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java
@@ -76,7 +76,7 @@ public static void init() {
if (!Utils.isInTheEnd()) return;
if (!SkyblockerConfigManager.get().locations.end.hudEnabled) return;
- EndHudWidget.INSTANCE.render(drawContext, SkyblockerConfigManager.get().locations.end.enableBackground);
+ EndHudWidget.INSTANCE.render(drawContext, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
});
ClientChunkEvents.CHUNK_LOAD.register((world, chunk) -> {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
new file mode 100644
index 0000000000..db3bbadc0d
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
@@ -0,0 +1,16 @@
+package de.hysky.skyblocker.skyblock.garden;
+
+import de.hysky.skyblocker.config.SkyblockerConfigManager;
+import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudFarmingWidget;
+import de.hysky.skyblocker.utils.Location;
+import de.hysky.skyblocker.utils.Utils;
+import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
+
+public class FarmingHud {
+ public static void init() {
+ HudRenderCallback.EVENT.register((context, tickDelta) -> {
+ if (!SkyblockerConfigManager.get().locations.garden.farmingHud.enableHud || Utils.getLocation() != Location.GARDEN) return;
+ HudFarmingWidget.INSTANCE.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ });
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
new file mode 100644
index 0000000000..51c1c69e45
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
@@ -0,0 +1,31 @@
+package de.hysky.skyblocker.skyblock.garden;
+
+import de.hysky.skyblocker.config.HudConfigScreen;
+import de.hysky.skyblocker.config.SkyblockerConfig;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudFarmingWidget;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.text.Text;
+
+import java.util.List;
+
+public class FarmingHudConfigScreen extends HudConfigScreen {
+ public FarmingHudConfigScreen(Screen parent) {
+ super(Text.literal("Farming HUD Config"), parent, HudFarmingWidget.INSTANCE);
+ }
+
+ @SuppressWarnings("SuspiciousNameCombination")
+ @Override
+ protected List getConfigPos(SkyblockerConfig config) {
+ return List.of(
+ IntIntMutablePair.of(config.locations.garden.farmingHud.x, config.locations.garden.farmingHud.y)
+ );
+ }
+
+ @Override
+ protected void savePos(SkyblockerConfig configManager, List widgets) {
+ configManager.locations.garden.farmingHud.x = widgets.get(0).getX();
+ configManager.locations.garden.farmingHud.y = widgets.get(0).getY();
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java
new file mode 100644
index 0000000000..4c9bcf7f1f
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java
@@ -0,0 +1,12 @@
+package de.hysky.skyblocker.skyblock.tabhud.widget;
+
+import net.minecraft.text.Text;
+
+public class EmptyWidget extends Widget {
+ public EmptyWidget() {
+ super(Text.empty(), 0);
+ }
+
+ @Override
+ public void updateContent() {}
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/Widget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/Widget.java
index e37da75505..01a8720b5b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/Widget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/Widget.java
@@ -26,7 +26,7 @@
public abstract class Widget {
private final ArrayList components = new ArrayList<>();
- private int w = 0, h = 0;
+ protected int w = 0, h = 0;
private int x = 0, y = 0;
private final int color;
private final Text title;
@@ -93,6 +93,10 @@ private void pack() {
w = Math.max(w, BORDER_SZE_W + BORDER_SZE_E + Widget.txtRend.getWidth(title) + 4 + 4 + 1);
}
+ public final int getX() {
+ return this.x;
+ }
+
public final void setX(int x) {
this.x = x;
}
@@ -101,10 +105,6 @@ public final int getY() {
return this.y;
}
- public final int getX() {
- return this.x;
- }
-
public final void setY(int y) {
this.y = y;
}
@@ -113,10 +113,27 @@ public final int getWidth() {
return this.w;
}
+ public void setWidth(int width) {
+ this.w = width;
+ }
+
public final int getHeight() {
return this.h;
}
+ public void setHeight(int height) {
+ this.h = height;
+ }
+
+ public void setDimensions(int size) {
+ setDimensions(size, size);
+ }
+
+ public void setDimensions(int width, int height) {
+ this.w = width;
+ this.h = height;
+ }
+
/**
* Draw this widget with a background
*/
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
new file mode 100644
index 0000000000..4099f23ec1
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
@@ -0,0 +1,22 @@
+package de.hysky.skyblocker.skyblock.tabhud.widget.hud;
+
+import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+
+public class HudFarmingWidget extends Widget {
+ private static final MutableText TITLE = Text.literal("Farming").formatted(Formatting.YELLOW, Formatting.BOLD);
+ public static final HudFarmingWidget INSTANCE = new HudFarmingWidget();
+
+ public HudFarmingWidget() {
+ super(TITLE, Formatting.YELLOW.getColorValue());
+ update();
+ }
+
+ @Override
+ public void updateContent() {
+ addSimpleIcoText(Ico.HOE, "Farming ", Formatting.RESET, "Farming");
+ }
+}
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index ce8b56fea5..926d8a7abe 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -32,7 +32,6 @@
"text.autoconfig.skyblocker.option.general.experiments.enableSuperpairsSolver": "Enable Superpairs Solver",
"text.autoconfig.skyblocker.option.general.experiments.enableUltrasequencerSolver": "Enable Ultrasequencer Solver",
"text.autoconfig.skyblocker.option.general.acceptReparty": "Auto accept Reparty",
- "text.autoconfig.skyblocker.option.general.visitorHelper": "Visitor helper",
"text.autoconfig.skyblocker.option.general.etherwarpOverlay": "Etherwarp Overlay",
"text.autoconfig.skyblocker.option.general.fishing": "Fishing Helper",
"text.autoconfig.skyblocker.option.general.fishing.enableFishingHelper": "Enable Fishing Helper",
@@ -68,6 +67,8 @@
"text.autoconfig.skyblocker.option.general.tabHud.tabHudEnabled": "Enable fancy tab HUD",
"text.autoconfig.skyblocker.option.general.tabHud.tabHudScale": "Scale factor of fancy tab HUD",
"text.autoconfig.skyblocker.option.general.tabHud.tabHudScale.@Tooltip": "Value in %, relative to your vanilla GUI scale",
+ "text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground": "Enable HUD Background",
+ "text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground.@Tooltip": "Enables the background of the non-tab HUD.",
"text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames": "Plain Player Names",
"text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames.@Tooltip":"Enable to display player names without any special formatting on public islands.",
"text.autoconfig.skyblocker.option.general.tabHud.nameSorting": "Player Name Sorting Method",
@@ -201,7 +202,10 @@
"text.autoconfig.skyblocker.option.locations.spidersDen.relics.enableRelicsHelper": "Enable Hidden Relics Helper",
"text.autoconfig.skyblocker.option.locations.spidersDen.relics.highlightFoundRelics": "Highlight Found Relics",
"text.autoconfig.skyblocker.option.locations.garden": "Garden",
+ "text.autoconfig.skyblocker.option.locations.garden.farmingHud.enableHud": "Enable Farming HUD",
+ "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.dungeons": "Dungeons",
"text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints": "Dungeon Secret Waypoints",
"text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.enableRoomMatching": "Enable Room Matching",
@@ -313,7 +317,6 @@
"text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[1]": "\nFancy: Shows name, percentage, progress bar and an icon.",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[2]": "\nClassic: Shows name and percentage in a very simple box.",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.screen": "Dwarven HUD Config...",
- "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground": "Enable Background",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud": "Crystal Hollows Map",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.enabled": "Enabled",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.screen": "Crystal Hollows Map Placement Config...",
From 9de7936885b3f4e1b2988149717b51e35f1efa85 Mon Sep 17 00:00:00 2001
From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Date: Sat, 9 Mar 2024 21:57:33 -0500
Subject: [PATCH 2/5] Add Farming HUD
---
.../skyblock/garden/FarmingHud.java | 105 +++++++++++++++++-
.../skyblock/garden/VisitorHelper.java | 3 +-
.../skyblocker/skyblock/tabhud/util/Ico.java | 11 ++
.../tabhud/widget/CameraPositionWidget.java | 17 +--
.../tabhud/widget/hud/HudFarmingWidget.java | 45 +++++++-
.../de/hysky/skyblocker/utils/ItemUtils.java | 14 +++
6 files changed, 177 insertions(+), 18 deletions(-)
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
index db3bbadc0d..dba282c1a4 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
@@ -2,15 +2,116 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudFarmingWidget;
+import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
+import it.unimi.dsi.fastutil.floats.FloatLongPair;
+import it.unimi.dsi.fastutil.ints.IntLongPair;
+import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
+import it.unimi.dsi.fastutil.longs.LongPriorityQueue;
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
+import net.fabricmc.fabric.api.event.client.player.ClientPlayerBlockBreakEvents;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.item.ItemStack;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.Locale;
+import java.util.Queue;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class FarmingHud {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FarmingHud.class);
+ public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
+ private static final Pattern COUNTER = Pattern.compile("Counter: (?[\\d,]+) \\w+");
+ private static final Pattern FARMING_XP = Pattern.compile("§3\\+(?\\d+.?\\d*) Farming \\((?\\d+.?\\d*)%\\)");
+ private static final Deque counter = new ArrayDeque<>();
+ private static final LongPriorityQueue blockBreaks = new LongArrayFIFOQueue();
+ private static final Queue farmingXp = new ArrayDeque<>();
+ private static float farmingXpPercentProgress;
+
public static void init() {
HudRenderCallback.EVENT.register((context, tickDelta) -> {
- if (!SkyblockerConfigManager.get().locations.garden.farmingHud.enableHud || Utils.getLocation() != Location.GARDEN) return;
- HudFarmingWidget.INSTANCE.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ if (shouldRender()) {
+ if (!counter.isEmpty() && counter.peek().rightLong() + 10_000 < System.currentTimeMillis()) {
+ counter.poll();
+ }
+ if (!blockBreaks.isEmpty() && blockBreaks.firstLong() + 1000 < System.currentTimeMillis()) {
+ blockBreaks.dequeueLong();
+ }
+ if (!farmingXp.isEmpty() && farmingXp.peek().rightLong() + 1000 < System.currentTimeMillis()) {
+ farmingXp.poll();
+ }
+
+ ItemStack stack = MinecraftClient.getInstance().player.getMainHandStack();
+ Matcher matcher = ItemUtils.getNbtTooltip(stack, FarmingHud.COUNTER);
+ if (matcher != null) {
+ try {
+ int count = NUMBER_FORMAT.parse(matcher.group("count")).intValue();
+ if (counter.isEmpty() || counter.peekLast().leftInt() != count) {
+ counter.offer(IntLongPair.of(count, System.currentTimeMillis()));
+ }
+ } catch (ParseException e) {
+ LOGGER.error("[Skyblocker Farming HUD] Failed to parse counter", e);
+ }
+ }
+
+ HudFarmingWidget.INSTANCE.update();
+ HudFarmingWidget.INSTANCE.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ }
+ });
+ ClientPlayerBlockBreakEvents.AFTER.register((world, player, pos, state) -> {
+ if (shouldRender()) {
+ blockBreaks.enqueue(System.currentTimeMillis());
+ }
});
+ ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
+ if (shouldRender() && overlay) {
+ Matcher matcher = FARMING_XP.matcher(message.getString());
+ if (matcher.matches()) {
+ try {
+ farmingXp.offer(FloatLongPair.of(NUMBER_FORMAT.parse(matcher.group("xp")).floatValue(), System.currentTimeMillis()));
+ farmingXpPercentProgress = NUMBER_FORMAT.parse(matcher.group("percent")).floatValue();
+ } catch (ParseException e) {
+ LOGGER.error("[Skyblocker Farming HUD] Failed to parse farming xp", e);
+ }
+ }
+ }
+ });
+ }
+
+ private static boolean shouldRender() {
+ return SkyblockerConfigManager.get().locations.garden.farmingHud.enableHud && Utils.getLocation() == Location.GARDEN;
+ }
+
+ public static int counter() {
+ return counter.isEmpty() ? 0 : counter.peekLast().leftInt();
+ }
+
+ public static float cropsPerMinute() {
+ if (counter.isEmpty()) {
+ return 0;
+ }
+ IntLongPair first = counter.peek();
+ IntLongPair last = counter.peekLast();
+ return (float) (last.leftInt() - first.leftInt()) / (last.rightLong() - first.rightLong()) * 60_000f;
+ }
+
+ public static int blockBreaks() {
+ return blockBreaks.size();
+ }
+
+ public static float farmingXpPercentProgress() {
+ return farmingXpPercentProgress;
+ }
+
+ public static double farmingXpPerHour() {
+ return farmingXp.stream().mapToDouble(FloatLongPair::leftFloat).sum() * 3600;
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
index 4fd9eeb3da..df8d1e70ee 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
@@ -26,6 +26,7 @@
import java.text.NumberFormat;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
//TODO: check inventory items, sum all repeated items into one
@@ -110,7 +111,7 @@ private static void updateItemMap(String visitorName, String lore) {
String itemName = splitItemText[0].trim();
if (itemName.isEmpty()) return;
try {
- int amount = splitItemText.length == 2 ? NumberFormat.getInstance().parse(splitItemText[1].trim()).intValue() : 1;
+ int amount = splitItemText.length == 2 ? NumberFormat.getInstance(Locale.US).parse(splitItemText[1].trim()).intValue() : 1;
Object2IntMap visitorMap = itemMap.getOrDefault(visitorName, new Object2IntOpenHashMap<>());
visitorMap.putIfAbsent(itemName, amount);
itemMap.putIfAbsent(visitorName, visitorMap);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java
index 96ab35d502..4872435b44 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java
@@ -53,12 +53,23 @@ public class Ico {
public static final ItemStack COMPOSTER = new ItemStack(Items.COMPOSTER);
public static final ItemStack SAPLING = new ItemStack(Items.OAK_SAPLING);
public static final ItemStack SEEDS = new ItemStack(Items.WHEAT_SEEDS);
+ public static final ItemStack WHEAT = new ItemStack(Items.WHEAT);
+ public static final ItemStack CARROT = new ItemStack(Items.CARROT);
+ public static final ItemStack POTATO = new ItemStack(Items.POTATO);
+ public static final ItemStack SUGAR_CANE = new ItemStack(Items.SUGAR_CANE);
+ public static final ItemStack NETHER_WART = new ItemStack(Items.NETHER_WART);
+ public static final ItemStack MUSHROOM = new ItemStack(Items.RED_MUSHROOM);
+ public static final ItemStack CACTUS = new ItemStack(Items.CACTUS);
+ public static final ItemStack MELON = new ItemStack(Items.MELON);
+ public static final ItemStack PUMPKIN = new ItemStack(Items.PUMPKIN);
+ public static final ItemStack COCOA_BEANS = new ItemStack(Items.COCOA_BEANS);
public static final ItemStack MILESTONE = new ItemStack(Items.LODESTONE);
public static final ItemStack PICKAXE = new ItemStack(Items.IRON_PICKAXE);
public static final ItemStack NETHER_STAR = new ItemStack(Items.NETHER_STAR);
public static final ItemStack HEART_OF_THE_SEA = new ItemStack(Items.HEART_OF_THE_SEA);
public static final ItemStack EXPERIENCE_BOTTLE = new ItemStack(Items.EXPERIENCE_BOTTLE);
public static final ItemStack PINK_DYE = new ItemStack(Items.PINK_DYE);
+ public static final ItemStack LIME_DYE = new ItemStack(Items.LIME_DYE);
public static final ItemStack ENCHANTED_BOOK = new ItemStack(Items.ENCHANTED_BOOK);
public static final ItemStack SPIDER_EYE = new ItemStack(Items.SPIDER_EYE);
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/CameraPositionWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/CameraPositionWidget.java
index 9cff3d32fc..9aa4a50ec9 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/CameraPositionWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/CameraPositionWidget.java
@@ -8,8 +8,7 @@
import net.minecraft.util.math.MathHelper;
public class CameraPositionWidget extends Widget {
- private static final MutableText TITLE = Text.literal("Camera Pos").formatted(Formatting.DARK_PURPLE,
- Formatting.BOLD);
+ private static final MutableText TITLE = Text.literal("Camera Pos").formatted(Formatting.DARK_PURPLE, Formatting.BOLD);
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
public CameraPositionWidget() {
@@ -21,17 +20,7 @@ public void updateContent() {
double yaw = CLIENT.getCameraEntity().getYaw();
double pitch = CLIENT.getCameraEntity().getPitch();
- this.addComponent(
- new PlainTextComponent(Text.literal("Yaw: " + roundToDecimalPlaces(MathHelper.wrapDegrees(yaw), 3))));
- this.addComponent(new PlainTextComponent(
- Text.literal("Pitch: " + roundToDecimalPlaces(MathHelper.wrapDegrees(pitch), 3))));
-
- }
-
- // https://stackoverflow.com/a/33889423
- private static double roundToDecimalPlaces(double value, int decimalPlaces) {
- double shift = Math.pow(10, decimalPlaces);
-
- return Math.round(value * shift) / shift;
+ addComponent(new PlainTextComponent(Text.literal("Yaw: " + String.format("%.3f", MathHelper.wrapDegrees(yaw)))));
+ addComponent(new PlainTextComponent(Text.literal("Pitch: " + String.format("%.3f", MathHelper.wrapDegrees(pitch)))));
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
index 4099f23ec1..b6ac25f82b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
@@ -1,22 +1,65 @@
package de.hysky.skyblocker.skyblock.tabhud.widget.hud;
+import de.hysky.skyblocker.skyblock.garden.FarmingHud;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
+import de.hysky.skyblocker.skyblock.tabhud.widget.component.ProgressComponent;
+import de.hysky.skyblocker.utils.ItemUtils;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+import net.minecraft.util.math.MathHelper;
+
+import java.util.Map;
public class HudFarmingWidget extends Widget {
private static final MutableText TITLE = Text.literal("Farming").formatted(Formatting.YELLOW, Formatting.BOLD);
+ private 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),
+ Map.entry("THEORETICAL_HOE_CARROT_1", Ico.CARROT),
+ Map.entry("THEORETICAL_HOE_CARROT_2", Ico.CARROT),
+ Map.entry("THEORETICAL_HOE_CARROT_3", Ico.CARROT),
+ Map.entry("THEORETICAL_HOE_POTATO_1", Ico.POTATO),
+ Map.entry("THEORETICAL_HOE_POTATO_2", Ico.POTATO),
+ Map.entry("THEORETICAL_HOE_POTATO_3", Ico.POTATO),
+ Map.entry("THEORETICAL_HOE_CANE_1", Ico.SUGAR_CANE),
+ Map.entry("THEORETICAL_HOE_CANE_2", Ico.SUGAR_CANE),
+ Map.entry("THEORETICAL_HOE_CANE_3", Ico.SUGAR_CANE),
+ Map.entry("THEORETICAL_HOE_WARTs_1", Ico.NETHER_WART),
+ Map.entry("THEORETICAL_HOE_WARTs_2", Ico.NETHER_WART),
+ Map.entry("THEORETICAL_HOE_WARTs_3", Ico.NETHER_WART),
+ Map.entry("FUNGI_CUTTER", Ico.MUSHROOM),
+ Map.entry("CACTUS_KNIFE", Ico.CACTUS),
+ Map.entry("MELON_DICER", Ico.MELON),
+ Map.entry("PUMPKIN_DICER", Ico.PUMPKIN),
+ Map.entry("COCO_CHOPPER", Ico.COCOA_BEANS)
+ );
public static final HudFarmingWidget INSTANCE = new HudFarmingWidget();
+ private final MinecraftClient client = MinecraftClient.getInstance();
public HudFarmingWidget() {
super(TITLE, Formatting.YELLOW.getColorValue());
update();
}
+ @SuppressWarnings("DataFlowIssue")
@Override
public void updateContent() {
- addSimpleIcoText(Ico.HOE, "Farming ", Formatting.RESET, "Farming");
+ ItemStack icon = FARMING_TOOLS.getOrDefault(ItemUtils.getItemId(client.player.getMainHandStack()), Ico.HOE);
+ addSimpleIcoText(icon, "Counter: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter()));
+ addSimpleIcoText(icon, "Crops/min: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) FarmingHud.cropsPerMinute() / 100 * 100));
+ addSimpleIcoText(icon, "Blocks/s: ", Formatting.YELLOW, Integer.toString(FarmingHud.blockBreaks()));
+ addComponent(new ProgressComponent(Ico.HOE, Text.literal("Farming Level: "), FarmingHud.farmingXpPercentProgress(), Formatting.YELLOW.getColorValue()));
+ addSimpleIcoText(Ico.LIME_DYE, "Farming XP/h: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) FarmingHud.farmingXpPerHour()));
+
+ double yaw = client.getCameraEntity().getYaw();
+ double pitch = client.getCameraEntity().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)));
}
}
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
index 880ebe7679..70a8c241b2 100644
--- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
@@ -25,6 +25,7 @@
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Predicate;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
@@ -186,6 +187,19 @@ public static String getNbtTooltip(ItemStack item, Predicate predicate)
return null;
}
+ @Nullable
+ public static Matcher getNbtTooltip(ItemStack item, Pattern pattern) {
+ for (Text line : getNbtTooltips(item)) {
+ String string = line.getString();
+ Matcher matcher = pattern.matcher(string);
+ if (matcher.matches()) {
+ return matcher;
+ }
+ }
+
+ return null;
+ }
+
public static List getNbtTooltips(ItemStack item) {
NbtCompound displayNbt = item.getSubNbt("display");
if (displayNbt == null || !displayNbt.contains("Lore", NbtElement.LIST_TYPE)) {
From aa5c2265f7a82b06d09fc21168323082565d0260 Mon Sep 17 00:00:00 2001
From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Date: Sun, 10 Mar 2024 17:44:56 -0400
Subject: [PATCH 3/5] Update xp progress bar
---
.../skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
index b6ac25f82b..645bef9698 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
@@ -54,7 +54,7 @@ public void updateContent() {
addSimpleIcoText(icon, "Counter: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter()));
addSimpleIcoText(icon, "Crops/min: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) FarmingHud.cropsPerMinute() / 100 * 100));
addSimpleIcoText(icon, "Blocks/s: ", Formatting.YELLOW, Integer.toString(FarmingHud.blockBreaks()));
- addComponent(new ProgressComponent(Ico.HOE, Text.literal("Farming Level: "), FarmingHud.farmingXpPercentProgress(), Formatting.YELLOW.getColorValue()));
+ addComponent(new ProgressComponent(Ico.LANTERN, Text.literal("Farming Level: "), FarmingHud.farmingXpPercentProgress(), Formatting.GOLD.getColorValue()));
addSimpleIcoText(Ico.LIME_DYE, "Farming XP/h: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) FarmingHud.farmingXpPerHour()));
double yaw = client.getCameraEntity().getYaw();
From 477d26414d4f23c8b16aaa975fd78d4cd7f46c2c Mon Sep 17 00:00:00 2001
From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Date: Thu, 14 Mar 2024 20:20:40 -0400
Subject: [PATCH 4/5] Refactor Farming Hud
---
.../de/hysky/skyblocker/config/HudConfigScreen.java | 1 -
.../hysky/skyblocker/skyblock/garden/FarmingHud.java | 12 +++++++++---
.../skyblock/garden/FarmingHudConfigScreen.java | 3 +--
.../FarmingHudWidget.java} | 12 +++++++-----
4 files changed, 17 insertions(+), 11 deletions(-)
rename src/main/java/de/hysky/skyblocker/skyblock/{tabhud/widget/hud/HudFarmingWidget.java => garden/FarmingHudWidget.java} (89%)
diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
index 6884af8358..07109b460a 100644
--- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
@@ -52,7 +52,6 @@ public HudConfigScreen(Text title, Screen parent, List widgets) {
@Override
public final void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
- renderBackground(context, mouseX, mouseY, delta);
renderWidget(context, widgets);
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
index dba282c1a4..ab504d6daa 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
@@ -1,14 +1,16 @@
package de.hysky.skyblocker.skyblock.garden;
+import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudFarmingWidget;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
+import de.hysky.skyblocker.utils.scheduler.Scheduler;
import it.unimi.dsi.fastutil.floats.FloatLongPair;
import it.unimi.dsi.fastutil.ints.IntLongPair;
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
import it.unimi.dsi.fastutil.longs.LongPriorityQueue;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.event.client.player.ClientPlayerBlockBreakEvents;
@@ -26,6 +28,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
+
public class FarmingHud {
private static final Logger LOGGER = LoggerFactory.getLogger(FarmingHud.class);
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
@@ -62,8 +66,8 @@ public static void init() {
}
}
- HudFarmingWidget.INSTANCE.update();
- HudFarmingWidget.INSTANCE.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ FarmingHudWidget.INSTANCE.update();
+ FarmingHudWidget.INSTANCE.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
}
});
ClientPlayerBlockBreakEvents.AFTER.register((world, player, pos, state) -> {
@@ -84,6 +88,8 @@ public static void init() {
}
}
});
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("hud").then(literal("farming")
+ .executes(Scheduler.queueOpenScreenCommand(() -> new FarmingHudConfigScreen(null)))))));
}
private static boolean shouldRender() {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
index 51c1c69e45..5384d47a66 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java
@@ -3,7 +3,6 @@
import de.hysky.skyblocker.config.HudConfigScreen;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
-import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudFarmingWidget;
import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
@@ -12,7 +11,7 @@
public class FarmingHudConfigScreen extends HudConfigScreen {
public FarmingHudConfigScreen(Screen parent) {
- super(Text.literal("Farming HUD Config"), parent, HudFarmingWidget.INSTANCE);
+ super(Text.literal("Farming HUD Config"), parent, FarmingHudWidget.INSTANCE);
}
@SuppressWarnings("SuspiciousNameCombination")
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
similarity index 89%
rename from src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
rename to src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
index 645bef9698..6ddb0e05e6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudFarmingWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java
@@ -1,6 +1,6 @@
-package de.hysky.skyblocker.skyblock.tabhud.widget.hud;
+package de.hysky.skyblocker.skyblock.garden;
-import de.hysky.skyblocker.skyblock.garden.FarmingHud;
+import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
@@ -15,7 +15,7 @@
import java.util.Map;
-public class HudFarmingWidget extends Widget {
+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(
Map.entry("THEORETICAL_HOE_WHEAT_1", Ico.WHEAT),
@@ -39,11 +39,13 @@ public class HudFarmingWidget extends Widget {
Map.entry("PUMPKIN_DICER", Ico.PUMPKIN),
Map.entry("COCO_CHOPPER", Ico.COCOA_BEANS)
);
- public static final HudFarmingWidget INSTANCE = new HudFarmingWidget();
+ public static final FarmingHudWidget INSTANCE = new FarmingHudWidget();
private final MinecraftClient client = MinecraftClient.getInstance();
- public HudFarmingWidget() {
+ public FarmingHudWidget() {
super(TITLE, Formatting.YELLOW.getColorValue());
+ setX(SkyblockerConfigManager.get().locations.garden.farmingHud.x);
+ setY(SkyblockerConfigManager.get().locations.garden.farmingHud.y);
update();
}
From 5cf396aa564ba3b93762f914cc2334d48596ab2e Mon Sep 17 00:00:00 2001
From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
Date: Sun, 17 Mar 2024 16:35:06 -0400
Subject: [PATCH 5/5] Fix Farming Hud counter regex
---
.../java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
index ab504d6daa..95c72241c6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java
@@ -33,7 +33,7 @@
public class FarmingHud {
private static final Logger LOGGER = LoggerFactory.getLogger(FarmingHud.class);
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
- private static final Pattern COUNTER = Pattern.compile("Counter: (?[\\d,]+) \\w+");
+ private static final Pattern COUNTER = Pattern.compile("Counter: (?[\\d,]+) .+");
private static final Pattern FARMING_XP = Pattern.compile("§3\\+(?\\d+.?\\d*) Farming \\((?\\d+.?\\d*)%\\)");
private static final Deque counter = new ArrayDeque<>();
private static final LongPriorityQueue blockBreaks = new LongArrayFIFOQueue();