aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java88
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java42
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java12
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java35
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java61
8 files changed, 149 insertions, 103 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
index f5e0461d..42034d9f 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
@@ -6,6 +6,7 @@ import de.hysky.skyblocker.events.DungeonEvents;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.dungeon.secrets.Room;
import de.hysky.skyblocker.utils.Constants;
+import de.hysky.skyblocker.utils.Resettable;
import de.hysky.skyblocker.utils.Tickable;
import de.hysky.skyblocker.utils.render.Renderable;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
@@ -16,7 +17,7 @@ import java.util.Set;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
-public abstract class DungeonPuzzle implements Tickable, Renderable {
+public abstract class DungeonPuzzle implements Tickable, Renderable, Resettable {
protected final String puzzleName;
@NotNull
private final Set<String> roomNames;
@@ -46,13 +47,14 @@ public abstract class DungeonPuzzle implements Tickable, Renderable {
}
return Command.SINGLE_SUCCESS;
})))))));
- ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> reset());
+ ClientPlayConnectionEvents.JOIN.register(this);
}
public boolean shouldSolve() {
return shouldSolve;
}
+ @Override
public void reset() {
shouldSolve = false;
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
index 30119204..98d32c68 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
@@ -1,39 +1,85 @@
package de.hysky.skyblocker.skyblock.dungeon.puzzle;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.chat.ChatFilterResult;
-import de.hysky.skyblocker.utils.chat.ChatPatternListener;
+import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
+import de.hysky.skyblocker.skyblock.dungeon.secrets.Room;
+import de.hysky.skyblocker.utils.render.RenderHelper;
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
+import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;
+import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
+import net.minecraft.util.hit.HitResult;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.Box;
+import net.minecraft.world.World;
+import java.util.List;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-public class ThreeWeirdos extends ChatPatternListener {
- public ThreeWeirdos() {
- super("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest\\!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest\\!)$");
+public class ThreeWeirdos extends DungeonPuzzle {
+ protected static final Pattern PATTERN = Pattern.compile("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest!)$");
+ private static final float[] GREEN_COLOR_COMPONENTS = new float[]{0, 1, 0};
+ private static BlockPos pos;
+
+ private ThreeWeirdos() {
+ super("three-weirdos", "three-chests");
+ ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
+ World world = MinecraftClient.getInstance().world;
+ if (overlay || !shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos || world == null || !DungeonManager.isCurrentRoomMatched()) return;
+
+ @SuppressWarnings("DataFlowIssue")
+ Matcher matcher = PATTERN.matcher(Formatting.strip(message.getString()));
+ if (!matcher.matches()) return;
+ String name = matcher.group(1);
+ Room room = DungeonManager.getCurrentRoom();
+
+ checkForNPC(world, room, new BlockPos(13, 69, 24), name);
+ checkForNPC(world, room, new BlockPos(15, 69, 25), name);
+ checkForNPC(world, room, new BlockPos(17, 69, 24), name);
+ });
+ UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> {
+ if (blockHitResult.getType() == HitResult.Type.BLOCK && blockHitResult.getBlockPos().equals(pos)) {
+ pos = null;
+ }
+ return ActionResult.PASS;
+ });
}
- @Override
- public ChatFilterResult state() {
- return SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos ? null : ChatFilterResult.PASS;
+ public static void init() {
+ new ThreeWeirdos();
}
- @Override
- public boolean onMatch(Text message, Matcher matcher) {
- MinecraftClient client = MinecraftClient.getInstance();
- if (client.player == null || client.world == null) return false;
- client.world.getEntitiesByClass(
+ private void checkForNPC(World world, Room room, BlockPos relative, String name) {
+ BlockPos npcPos = room.relativeToActual(relative);
+ List<ArmorStandEntity> npcs = world.getEntitiesByClass(
ArmorStandEntity.class,
- client.player.getBoundingBox().expand(3),
- entity -> {
- Text customName = entity.getCustomName();
- return customName != null && customName.getString().equals(matcher.group(1));
- }
- ).forEach(
- entity -> entity.setCustomName(Text.of(Formatting.GREEN + matcher.group(1)))
+ Box.enclosing(npcPos, npcPos),
+ entity -> entity.getName().getString().equals(name)
);
- return false;
+ if (!npcs.isEmpty()) {
+ pos = room.relativeToActual(relative.add(1, 0, 0));
+ npcs.forEach(entity -> entity.setCustomName(Text.literal(name).formatted(Formatting.GREEN)));
+ }
+ }
+
+ @Override
+ public void tick(MinecraftClient client) {}
+
+ @Override
+ public void render(WorldRenderContext context) {
+ if (shouldSolve() && pos != null) {
+ RenderHelper.renderFilled(context, pos, GREEN_COLOR_COMPONENTS, 0.5f, true);
+ }
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ pos = null;
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
index a72b955b..00b09dcf 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
@@ -156,7 +156,7 @@ public class BarPositioner {
SizeRule.freeSize(25, 2, 6)),
HOTBAR_TOP(true, true,
- (scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth / 2 - 91, scaledHeight - 23),
+ (scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth / 2 - 91, scaledHeight - (FancyStatusBars.isExperienceFancyBarVisible() ? 23 : 35)),
SizeRule.targetSize(12, 182, 2),
anchorPosition -> new ScreenRect(anchorPosition.x(), anchorPosition.y() - 20, 182, 20)),
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java
index 141a48ed..72c1370c 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java
@@ -41,6 +41,16 @@ public class FancyStatusBars {
public static BarPositioner barPositioner = new BarPositioner();
public static Map<String, StatusBar> statusBars = new HashMap<>();
+ public static boolean isHealthFancyBarVisible() {
+ StatusBar health = statusBars.get("health");
+ return health.anchor != null || health.inMouse;
+ }
+
+ public static boolean isExperienceFancyBarVisible() {
+ StatusBar experience = statusBars.get("experience");
+ return experience.anchor != null || experience.inMouse;
+ }
+
public static void init() {
statusBars.put("health", new StatusBar(new Identifier(SkyblockerMod.NAMESPACE, "bars/icons/health"),
new Color[]{new Color(255, 0, 0), new Color(255, 220, 0)},
@@ -177,6 +187,12 @@ public class FancyStatusBars {
ScreenPos anchorPosition = barAnchor.getAnchorPosition(width, height);
BarPositioner.SizeRule sizeRule = barAnchor.getSizeRule();
+ int targetSize = sizeRule.targetSize();
+ boolean visibleHealthMove = barAnchor == BarPositioner.BarAnchor.HOTBAR_TOP && !isHealthFancyBarVisible();
+ if (visibleHealthMove) {
+ targetSize /= 2;
+ }
+
if (sizeRule.isTargetSize()) {
for (int row = 0; row < barPositioner.getRowCount(barAnchor); row++) {
LinkedList<StatusBar> barRow = barPositioner.getRow(barAnchor, row);
@@ -188,13 +204,13 @@ public class FancyStatusBars {
totalSize += (statusBar.size = Math.clamp(statusBar.size, sizeRule.minSize(), sizeRule.maxSize()));
whileLoop:
- while (totalSize != sizeRule.targetSize()) {
- if (totalSize > sizeRule.targetSize()) {
+ while (totalSize != targetSize) {
+ if (totalSize > targetSize) {
for (StatusBar statusBar : barRow) {
if (statusBar.size > sizeRule.minSize()) {
statusBar.size--;
totalSize--;
- if (totalSize == sizeRule.targetSize()) break whileLoop;
+ if (totalSize == targetSize) break whileLoop;
}
}
} else {
@@ -202,7 +218,7 @@ public class FancyStatusBars {
if (statusBar.size < sizeRule.maxSize()) {
statusBar.size++;
totalSize++;
- if (totalSize == sizeRule.targetSize()) break whileLoop;
+ if (totalSize == targetSize) break whileLoop;
}
}
}
@@ -219,10 +235,12 @@ public class FancyStatusBars {
// Update the positions
float widthPerSize;
if (sizeRule.isTargetSize())
- widthPerSize = (float) sizeRule.totalWidth() / sizeRule.targetSize();
+ widthPerSize = (float) sizeRule.totalWidth() / targetSize;
else
widthPerSize = sizeRule.widthPerSize();
+ if (visibleHealthMove) widthPerSize /= 2;
+
int currSize = 0;
int rowSize = barRow.size();
for (int i = 0; i < rowSize; i++) {
@@ -243,7 +261,7 @@ public class FancyStatusBars {
statusBar.size = Math.clamp(statusBar.size, sizeRule.minSize(), sizeRule.maxSize());
float x = barAnchor.isRight() ?
- anchorPosition.x() + currSize * widthPerSize :
+ anchorPosition.x() + (visibleHealthMove ? sizeRule.totalWidth() / 2.f : 0) + currSize * widthPerSize :
anchorPosition.x() - currSize * widthPerSize - statusBar.size * widthPerSize;
statusBar.setX(MathHelper.ceil(x) + offsetX);
@@ -263,17 +281,21 @@ public class FancyStatusBars {
}
}
+ public static boolean isEnabled() {
+ return SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars && !Utils.isInTheRift();
+ }
+
public boolean render(DrawContext context, int scaledWidth, int scaledHeight) {
var player = client.player;
- if (!SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars || player == null || Utils.isInTheRift())
+ if (!isEnabled() || player == null)
return false;
Collection<StatusBar> barCollection = statusBars.values();
- for (StatusBar value : barCollection) {
- value.render(context, -1, -1, client.getLastFrameDuration());
+ for (StatusBar statusBar : barCollection) {
+ if (statusBar.anchor != null) statusBar.render(context, -1, -1, client.getLastFrameDuration());
}
for (StatusBar statusBar : barCollection) {
- if (statusBar.showText()) statusBar.renderText(context);
+ if (statusBar.anchor != null && statusBar.showText()) statusBar.renderText(context);
}
StatusBarTracker.Resource health = statusBarTracker.getHealth();
statusBars.get("health").updateValues(health.value() / (float) health.max(), health.overflow() / (float) health.max(), health.value());
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
index f8109852..467691fd 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
@@ -93,7 +93,7 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
public float fill = 0;
public float overflowFill = 0;
- public boolean ghost = false;
+ public boolean inMouse = false;
private Object value = "";
@@ -119,7 +119,7 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (width <= 0) return;
// half works lol. only puts transparency on the filler of the bar
- if (ghost) context.setShaderColor(1f, 1f, 1f, 0.25f);
+ if (inMouse) context.setShaderColor(1f, 1f, 1f, 0.25f);
switch (iconPosition) {
case LEFT -> context.drawGuiTexture(icon, x, y, 9, 9);
case RIGHT -> context.drawGuiTexture(icon, x + width - 9, y, 9, 9);
@@ -134,7 +134,7 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
if (hasOverflow && overflowFill > 0) {
RenderHelper.renderNineSliceColored(context, BAR_FILL, barX + 1, y + 2, (int) ((barWith - 2) * overflowFill), 5, colors[1]);
}
- if (ghost) context.setShaderColor(1f, 1f, 1f, 1f);
+ if (inMouse) context.setShaderColor(1f, 1f, 1f, 1f);
//context.drawText(MinecraftClient.getInstance().textRenderer, gridX + " " + gridY + " s:" + size , x, y-9, Colors.WHITE, true);
}
@@ -164,19 +164,19 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
int temp_x = x;
int temp_y = y;
int temp_width = width;
- boolean temp_ghost = ghost;
+ boolean temp_ghost = inMouse;
x = mouseX;
y = mouseY;
width = 100;
- ghost = false;
+ inMouse = false;
render(context, mouseX, mouseY, delta);
x = temp_x;
y = temp_y;
width = temp_width;
- ghost = temp_ghost;
+ inMouse = temp_ghost;
}
// GUI shenanigans
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
index d1009a25..df072710 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
@@ -277,7 +277,7 @@ public class StatusBarsConfigScreen extends Screen {
public void removed() {
super.removed();
FancyStatusBars.statusBars.values().forEach(statusBar -> statusBar.setOnClick(null));
- if (cursorBar != null) cursorBar.ghost = false;
+ if (cursorBar != null) cursorBar.inMouse = false;
FancyStatusBars.updatePositions();
assert client != null;
GLFW.glfwSetCursor(client.getWindow().getHandle(), 0);
@@ -292,7 +292,7 @@ public class StatusBarsConfigScreen extends Screen {
private void onBarClick(StatusBar statusBar, int button, int mouseX, int mouseY) {
if (button == 0) {
cursorBar = statusBar;
- cursorBar.ghost = true;
+ cursorBar.inMouse = true;
if (statusBar.anchor != null)
FancyStatusBars.barPositioner.removeBar(statusBar.anchor, statusBar.gridY, statusBar);
FancyStatusBars.updatePositions();
@@ -321,7 +321,7 @@ public class StatusBarsConfigScreen extends Screen {
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
if (cursorBar != null) {
- cursorBar.ghost = false;
+ cursorBar.inMouse = false;
cursorBar = null;
FancyStatusBars.updatePositions();
checkNullAnchor(FancyStatusBars.statusBars.values());
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java
index a6adf66b..5fa517cc 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java
@@ -1,20 +1,16 @@
package de.hysky.skyblocker.skyblock.quicknav;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
-
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.QuickNavigationConfig;
-import de.hysky.skyblocker.utils.Utils;
+import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.datafixer.ItemStackComponentizationFixer;
-import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
-import net.fabricmc.fabric.api.client.screen.v1.Screens;
import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,16 +21,6 @@ import java.util.regex.PatternSyntaxException;
public class QuickNav {
private static final Logger LOGGER = LoggerFactory.getLogger(QuickNav.class);
- public static void init() {
- ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
- if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().quickNav.enableQuickNav && screen instanceof HandledScreen<?> && client.player != null && !client.player.isCreative()) {
- String screenTitle = screen.getTitle().getString().trim();
- List<QuickNavButton> buttons = QuickNav.init(screenTitle);
- for (QuickNavButton button : buttons) Screens.getButtons(screen).add(button);
- }
- });
- }
-
public static List<QuickNavButton> init(String screenTitle) {
List<QuickNavButton> buttons = new ArrayList<>();
QuickNavigationConfig data = SkyblockerConfigManager.get().quickNav;
@@ -51,6 +37,8 @@ public class QuickNav {
if (data.button10.render) buttons.add(parseButton(data.button10, screenTitle, 9));
if (data.button11.render) buttons.add(parseButton(data.button11, screenTitle, 10));
if (data.button12.render) buttons.add(parseButton(data.button12, screenTitle, 11));
+ if (data.button13.render) buttons.add(parseButton(data.button13, screenTitle, 12));
+ if (data.button14.render) buttons.add(parseButton(data.button14, screenTitle, 13));
} catch (CommandSyntaxException e) {
LOGGER.error("[Skyblocker] Failed to initialize Quick Nav Button", e);
}
@@ -58,22 +46,19 @@ public class QuickNav {
}
private static QuickNavButton parseButton(QuickNavigationConfig.QuickNavItem buttonInfo, String screenTitle, int id) throws CommandSyntaxException {
- QuickNavigationConfig.ItemData itemData = buttonInfo.item;
- ItemStack stack = ItemStackComponentizationFixer.fromComponentsString(itemData.id, Math.clamp(itemData.count, 1, 99), itemData.components);
- boolean uiTitleMatches = false;
+ QuickNavigationConfig.ItemData itemData = buttonInfo.itemData;
+ ItemStack stack = itemData != null && itemData.item != null && itemData.components != null ? ItemStackComponentizationFixer.fromComponentsString(itemData.item.toString(), Math.clamp(itemData.count, 1, 99), itemData.components) : new ItemStack(Items.BARRIER);
+ boolean uiTitleMatches = false;
try {
uiTitleMatches = screenTitle.matches(buttonInfo.uiTitle);
} catch (PatternSyntaxException e) {
- LOGGER.error("[Skyblocker] Failed to parse Quick Nav Button", e);
+ LOGGER.error("[Skyblocker] Failed to parse Quick Nav Button with regex: {}", buttonInfo.uiTitle, e);
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player != null) {
- player.sendMessage(Text.of(Formatting.RED + "[Skyblocker] Invalid regex in quicknav button " + (id + 1) + "!"), false);
+ player.sendMessage(Constants.PREFIX.get().append(Text.literal("Invalid regex in Quick Nav Button " + (id + 1) + "!").formatted(Formatting.RED)), false);
}
}
- return new QuickNavButton(id,
- uiTitleMatches,
- buttonInfo.clickEvent,
- stack);
+ return new QuickNavButton(id, uiTitleMatches, buttonInfo.clickEvent, stack);
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java
index 7db78590..f9ca0940 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java
@@ -1,7 +1,6 @@
package de.hysky.skyblocker.skyblock.quicknav;
import com.mojang.blaze3d.systems.RenderSystem;
-
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.api.EnvType;
@@ -16,7 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
-@Environment(value=EnvType.CLIENT)
+@Environment(value = EnvType.CLIENT)
public class QuickNavButton extends ClickableWidget {
private final int index;
private boolean toggled;
@@ -25,18 +24,24 @@ public class QuickNavButton extends ClickableWidget {
/**
* Checks if the current tab is a top tab based on its index.
- * @return true if the index is less than 6, false otherwise.
+ *
+ * @return true if the index is less than 7, false otherwise.
*/
private boolean isTopTab() {
- return index < 6;
+ return index < 7;
+ }
+
+ public boolean toggled() {
+ return toggled;
}
/**
* Constructs a new QuickNavButton with the given parameters.
- * @param index the index of the button.
+ *
+ * @param index the index of the button.
* @param toggled the toggled state of the button.
* @param command the command to execute when the button is clicked.
- * @param icon the icon to display on the button.
+ * @param icon the icon to display on the button.
*/
public QuickNavButton(int index, boolean toggled, String command, ItemStack icon) {
super(0, 0, 26, 32, Text.empty());
@@ -49,18 +54,18 @@ public class QuickNavButton extends ClickableWidget {
private void updateCoordinates() {
Screen screen = MinecraftClient.getInstance().currentScreen;
if (screen instanceof HandledScreen<?> handledScreen) {
- int x = ((HandledScreenAccessor)handledScreen).getX();
- int y = ((HandledScreenAccessor)handledScreen).getY();
- int h = ((HandledScreenAccessor)handledScreen).getBackgroundHeight();
- if (h > 166) --h; // why is this even a thing
- this.setX(x + this.index % 6 * 26 + 4);
- this.setY(this.index < 6 ? y - 26 : y + h - 4);
+ int x = ((HandledScreenAccessor) handledScreen).getX();
+ int y = ((HandledScreenAccessor) handledScreen).getY();
+ int h = ((HandledScreenAccessor) handledScreen).getBackgroundHeight();
+ this.setX(x + this.index % 7 * 25);
+ this.setY(this.index < 7 ? y - 28 : y + h - 4);
}
}
/**
* Handles click events. If the button is not currently toggled,
* it sets the toggled state to true and sends a message with the command after cooldown.
+ *
* @param mouseX the x-coordinate of the mouse click
* @param mouseY the y-coordinate of the mouse click
*/
@@ -78,9 +83,10 @@ public class QuickNavButton extends ClickableWidget {
* The method first updates the coordinates of the button,
* then calculates appropriate values for rendering based on its current state,
* and finally draws both the background and icon of the button on screen.
+ *
* @param context the context in which to render the button
- * @param mouseX the x-coordinate of the mouse cursor
- * @param mouseY the y-coordinate of the mouse cursor
+ * @param mouseX the x-coordinate of the mouse cursor
+ * @param mouseY the y-coordinate of the mouse cursor
*/
@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
@@ -88,31 +94,16 @@ public class QuickNavButton extends ClickableWidget {
RenderSystem.disableDepthTest();
// Construct the texture identifier based on the index and toggled state
- String tabType = isTopTab() ? "top" : "bottom";
- Identifier BUTTON_TEXTURES = new Identifier("container/creative_inventory/tab_" + tabType +
- (toggled ? "_selected_" : "_unselected_") + 2);
+ Identifier tabTexture = new Identifier("container/creative_inventory/tab_" + (isTopTab() ? "top" : "bottom") + "_" + (toggled ? "selected" : "unselected") + "_" + (index % 7 + 1));
// Render the button texture
- int y = this.getY();
- if (this.toggled) {
- if (this.index < 6) y -= 2;
- } else {
- y += (this.index >= 6) ? 4 : -2;
- }
- int height = this.height - ((this.toggled ) ? 0 : 4);
-
- context.drawGuiTexture(BUTTON_TEXTURES, this.getX(), y, this.width, height);
-
+ context.drawGuiTexture(tabTexture, this.getX(), this.getY(), this.width, this.height);
// Render the button icon
- int yOffset = !this.toggled && this.index < 6 ? 1 : 0;
- context.drawItem(this.icon, this.getX() + 5, this.getY() + 6 + yOffset);
-
+ int yOffset = this.index < 7 ? 1 : -1;
+ context.drawItem(this.icon, this.getX() + 5, this.getY() + 8 + yOffset);
RenderSystem.enableDepthTest();
}
- @Override
- protected void appendClickableNarrations(NarrationMessageBuilder builder) {
- // TODO Auto-generated method stub
-
- }
+ @Override
+ protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
}