diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven')
4 files changed, 65 insertions, 163 deletions
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 7b15c61e..f113561f 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.SkyblockerMod; 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.client.util.math.MatrixStack; 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 class CrystalsHud { }); } - 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 @@ public class CrystalsHud { } /** - * 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 @@ public class CrystalsHud { * 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 b4e423e9..15e605b9 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<IntIntMutablePair> 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<Widget> 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<Widget> 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 608873c0..8eb15935 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.HudCommsWidget; 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 class DwarvenHud { .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 class DwarvenHud { }); } - /** - * 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<IntIntPair,IntIntPair> getDimForConfig(List<Commission> 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<Commission> 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 class DwarvenHud { * @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<Commission> 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 class DwarvenHud { } public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> 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<Commission> 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 d5dc19f2..79a139f9 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<DwarvenHud.Commission> 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<IntIntPair,IntIntPair> 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<IntIntMutablePair> 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<IntIntPair,IntIntPair> 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<Widget> 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<Widget> 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(); } } |