aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock
diff options
context:
space:
mode:
authorSerhan <serhanduzce@gmail.com>2022-06-16 12:34:35 +0300
committerGitHub <noreply@github.com>2022-06-16 12:34:35 +0300
commit5f323aaf6f26aba3a2f33eea9ed88e1ee40cc4f9 (patch)
tree856b91f6a6c8632b24ef05d1898c0ba1f847585b /src/main/java/me/xmrvizzy/skyblocker/skyblock
parent4afe31dca21b94c102099549800d4fa1cb1bbe6d (diff)
parent6c268d4f5b5d9447d9cd7ca4cb5afe2066198c97 (diff)
downloadSkyblocker-5f323aaf6f26aba3a2f33eea9ed88e1ee40cc4f9.tar.gz
Skyblocker-5f323aaf6f26aba3a2f33eea9ed88e1ee40cc4f9.tar.bz2
Skyblocker-5f323aaf6f26aba3a2f33eea9ed88e1ee40cc4f9.zip
Merge branch 'SkyblockerMod:master' into master
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java133
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java277
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/StatusBarTracker.java110
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/OldLever.java2
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java43
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java17
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java32
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemFixerUpper.java70
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java13
9 files changed, 462 insertions, 235 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
index 2638b0a6..00f32459 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
@@ -9,6 +9,7 @@ import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
+import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
@@ -18,7 +19,9 @@ import net.minecraft.nbt.*;
import net.minecraft.util.Identifier;
import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -26,82 +29,95 @@ import java.util.regex.Pattern;
public class BackpackPreview extends DrawableHelper {
private static final Identifier TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/inventory_background.png");
private static final BackpackPreview instance = new BackpackPreview();
+ private static final Pattern PROFILE_PATTERN = Pattern.compile("Profile: ([a-zA-Z]+)");
private static final Pattern ECHEST_PATTERN = Pattern.compile("Ender Chest.*\\((\\d+)/\\d+\\)");
private static final Pattern BACKPACK_PATTERN = Pattern.compile("Backpack.*\\((\\d+)/\\d+\\)");
private static final int STORAGE_SIZE = 27;
private static final Inventory[] storage = new Inventory[STORAGE_SIZE];
private static final boolean[] dirty = new boolean[STORAGE_SIZE];
- private static boolean loaded = false;
+
+ private static String loaded = ""; // uuid + sb profile currently loaded
+ private static Path save_dir = null;
public static void tick() {
+ Utils.sbChecker(); // force update isOnSkyblock to prevent crash on disconnect
if (Utils.isOnSkyblock) {
- for (int index = 0; index < STORAGE_SIZE; ++index)
- if (dirty[index]) saveStorage(index);
- if (MinecraftClient.getInstance().currentScreen != null) {
- String title = MinecraftClient.getInstance().currentScreen.getTitle().getString();
- int index = getStorageIndexFromTitle(title);
- if (index != -1) dirty[index] = true;
+ // save all dirty storages
+ saveStorage();
+ // update save dir based on uuid and sb profile
+ String uuid = MinecraftClient.getInstance().getSession().getUuid().replaceAll("-", "");
+ String profile = getSkyblockProfile();
+ if (uuid != null && profile != null) {
+ save_dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + uuid + "/" + profile);
+ save_dir.toFile().mkdirs();
+ if (loaded.equals(uuid + "/" + profile)) {
+ // mark currently opened storage as dirty
+ if (MinecraftClient.getInstance().currentScreen != null) {
+ String title = MinecraftClient.getInstance().currentScreen.getTitle().getString();
+ int index = getStorageIndexFromTitle(title);
+ if (index != -1) dirty[index] = true;
+ }
+ } else {
+ // load storage again because uuid/profile changed
+ loaded = uuid + "/" + profile;
+ loadStorage();
+ }
}
}
}
- private static File getSaveDir() {
- String uuid = MinecraftClient.getInstance().getSession().getUuid();
- File dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + uuid).toFile();
- dir.mkdirs();
- return dir;
- }
-
- public static void loadStorage(HandledScreen screen) {
- if (!loaded) {
- String title = screen.getTitle().getString();
- if (title.equals("Storage")) {
- for (int index = 0; index < STORAGE_SIZE; ++index) {
- File file = new File(getSaveDir().getPath(), index + ".nbt");
- if (file.isFile()) {
- try {
- NbtCompound root = NbtIo.read(file);
- storage[index] = new DummyInventory(root);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ public static void loadStorage() {
+ assert(save_dir != null);
+ for (int index = 0; index < STORAGE_SIZE; ++index) {
+ storage[index] = null;
+ dirty[index] = false;
+ File file = save_dir.resolve(index + ".nbt").toFile();
+ if (file.isFile()) {
+ try {
+ NbtCompound root = NbtIo.read(file);
+ storage[index] = new DummyInventory(root);
+ } catch (Exception e) {
+ e.printStackTrace();
}
- loaded = true;
}
}
}
- private static void saveStorage(int index) {
- File file = new File(getSaveDir().getPath(), index + ".nbt");
- if (storage[index] != null) {
- try {
- NbtCompound root = new NbtCompound();
- NbtList list = new NbtList();
- for (int i = 9; i < storage[index].size(); ++i) {
- ItemStack stack = storage[index].getStack(i);
- NbtCompound item = new NbtCompound();
- if (stack.isEmpty()) {
- item.put("id", NbtString.of("minecraft:air"));
- item.put("Count", NbtInt.of(1));
- } else {
- item.put("id", NbtString.of(stack.getItem().toString()));
- item.put("Count", NbtInt.of(stack.getCount()));
- item.put("tag", stack.getNbt());
+ private static void saveStorage() {
+ assert(save_dir != null);
+ for (int index = 0; index < STORAGE_SIZE; ++index) {
+ if (dirty[index]) {
+ if (storage[index] != null) {
+ try {
+ NbtCompound root = new NbtCompound();
+ NbtList list = new NbtList();
+ for (int i = 9; i < storage[index].size(); ++i) {
+ ItemStack stack = storage[index].getStack(i);
+ NbtCompound item = new NbtCompound();
+ if (stack.isEmpty()) {
+ item.put("id", NbtString.of("minecraft:air"));
+ item.put("Count", NbtInt.of(1));
+ } else {
+ item.put("id", NbtString.of(stack.getItem().toString()));
+ item.put("Count", NbtInt.of(stack.getCount()));
+ item.put("tag", stack.getNbt());
+ }
+ list.add(item);
+ }
+ root.put("list", list);
+ root.put("size", NbtInt.of(storage[index].size() - 9));
+ NbtIo.write(root, save_dir.resolve(index + ".nbt").toFile());
+ dirty[index] = false;
+ } catch (Exception e) {
+ e.printStackTrace();
}
- list.add(item);
}
- root.put("list", list);
- root.put("size", NbtInt.of(storage[index].size() - 9));
- NbtIo.write(root, file);
- } catch (Exception e) {
- e.printStackTrace();
}
}
}
- public static void updateStorage(HandledScreen screen) {
+ public static void updateStorage(HandledScreen<?> screen) {
String title = screen.getTitle().getString();
int index = getStorageIndexFromTitle(title);
if (index != -1) {
@@ -151,6 +167,19 @@ public class BackpackPreview extends DrawableHelper {
if (backpack.find()) return Integer.parseInt(backpack.group(1)) + 8;
return -1;
}
+
+ private static String getSkyblockProfile() {
+ Collection<PlayerListEntry> list = MinecraftClient.getInstance().getNetworkHandler().getPlayerList();
+ for (PlayerListEntry entry : list) {
+ if (entry.getDisplayName() != null) {
+ Matcher matcher = PROFILE_PATTERN.matcher(entry.getDisplayName().getString());
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+ }
+ }
+ return null;
+ }
}
class DummyInventory implements Inventory {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
index 5d3cf9c4..dd7ef478 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
@@ -7,164 +7,179 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class FancyStatusBars extends DrawableHelper {
- private static final MinecraftClient client = MinecraftClient.getInstance();
private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/bars.png");
- private static final Pattern ACTION_BAR_MANA = Pattern.compile("§b-\\d+ Mana \\(.*\\) +");
- private static final Pattern ACTION_BAR_STATUS = Pattern.compile("^§[6c](\\d+)/(\\d+)❤(\\+§c\\d+.)? +(?:§a(\\d+)§a❈ Defense|([^✎]*?))?(?: +§b(\\d+)/(\\d+)✎ +(?:Mana|§3(\\d+)ʬ))?(?: +(§[27].*))?$");
-
- private final Resource[] resources = new Resource[]{
- // Health
- new Resource(16733525),
- // Mana
- new Resource(5636095),
- // Defense
- new Resource(12106180),
- // Experience
- new Resource(8453920),
- };
-
- public boolean update(String actionBar) {
- if (!SkyblockerConfig.get().general.bars.enableBars) {
- if (SkyblockerConfig.get().messages.hideMana) {
- Matcher mana = ACTION_BAR_MANA.matcher(actionBar);
- if (mana.find()) {
- assert client.player != null;
- client.player.sendMessage(Text.of(actionBar.replace(mana.group(), "")), true);
- return true;
- }
- }
- return false;
- }
-
- Matcher matcher = ACTION_BAR_STATUS.matcher(actionBar);
- if (!matcher.matches())
- return false;
-
- resources[0].setMax(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)));
- if (matcher.group(4) != null) {
- int def = Integer.parseInt(matcher.group(4));
- resources[2].setFillLevel(def, (double) def / ((double) def + 100D));
- }
- if (matcher.group(6) != null) {
- int m = Integer.parseInt(matcher.group(6));
- if (matcher.group(8) != null)
- m += Integer.parseInt(matcher.group(8));
- resources[1].setMax(m, Integer.parseInt(matcher.group(7)));
- }
- assert client.player != null;
- resources[3].setFillLevel(client.player.experienceLevel, client.player.experienceProgress);
- StringBuilder sb = new StringBuilder();
- if (matcher.group(3) != null) {
- sb.append("§c").append(matcher.group(3));
- }
- if (SkyblockerConfig.get().messages.hideMana) {
- Matcher mana = ACTION_BAR_MANA.matcher(actionBar);
- if (!mana.find())
- appendIfNotNull(sb, matcher.group(5));
- } else {
- appendIfNotNull(sb, matcher.group(5));
- }
- appendIfNotNull(sb, matcher.group(9));
+ private final MinecraftClient client = MinecraftClient.getInstance();
+ private final StatusBarTracker statusBarTracker = SkyblockerMod.getInstance().statusBarTracker;
- if (!sb.isEmpty()) {
- assert client.player != null;
- client.player.sendMessage(Text.of(sb.toString()), true);
- }
+ private final StatusBar[] bars = new StatusBar[]{
+ new StatusBar(0, 16733525, 2), // Health Bar
+ new StatusBar(1, 5636095, 2), // Intelligence Bar
+ new StatusBar(2, 12106180, 1), // Defence Bar
+ new StatusBar(3, 8453920, 1), // Experience Bar
+ };
- return true;
+ // Positions to show the bars
+ // 0: Hotbar Layer 1, 1: Hotbar Layer 2, 2: Right of hotbar
+ // Anything outside the set values hides the bar
+ private final int[] anchorsX = new int[3];
+ private final int[] anchorsY = new int[3];
+
+ public FancyStatusBars() {
+ moveBar(0, 0);
+ moveBar(1, 0);
+ moveBar(2, 0);
+ moveBar(3, 0);
}
- private void appendIfNotNull(StringBuilder sb, String str) {
- if (str == null)
- return;
- if (!sb.isEmpty())
- sb.append(" ");
- sb.append(str);
+ private int fill(int value, int max) {
+ return (100 * value) / max;
}
- private static final int BAR_SPACING = 46;
-
public boolean render(MatrixStack matrices, int scaledWidth, int scaledHeight) {
- if (!SkyblockerConfig.get().general.bars.enableBars)
+ var player = client.player;
+ if (!SkyblockerConfig.get().general.bars.enableBars || player == null)
return false;
- int left = scaledWidth / 2 - 91;
- int top = scaledHeight - 35;
- RenderSystem.setShaderTexture(0, BARS);
- for (int i = 0; i < 4; i++) {
- this.drawTexture(matrices, left + i * BAR_SPACING, top, 0, 9 * i, 43, 9);
- int fillCount = resources[i].getFillCount();
- for (int j = 0; j < fillCount; j++) {
- this.drawTexture(matrices, left + 11 + i * BAR_SPACING, top, 43 + 31 * j, 9 * i, Resource.INNER_WIDTH, 9);
- }
- int fillLevel = resources[i].getFillLevel();
- if (0 < fillLevel)
- this.drawTexture(matrices, left + 11 + i * BAR_SPACING, top, 43 + 31 * fillCount, 9 * i, fillLevel, 9);
- }
+ anchorsX[0] = scaledWidth / 2 - 91;
+ anchorsY[0] = scaledHeight - 33;
+ anchorsX[1] = anchorsX[0];
+ anchorsY[1] = anchorsY[0] - 10;
+ anchorsX[2] = (scaledWidth / 2 + 91) + 2;
+ anchorsY[2] = scaledHeight - 16;
+
+ bars[0].update(statusBarTracker.getHealth());
+ bars[1].update(statusBarTracker.getMana());
+ int def = statusBarTracker.getDefense();
+ bars[2].fill[0] = fill(def, def + 100);
+ bars[2].text = def;
+ bars[3].fill[0] = (int) (32 * player.experienceProgress);
+ bars[3].text = player.experienceLevel;
+
+ // Update positions of bars from config
for (int i = 0; i < 4; i++) {
- renderText(matrices, resources[i].getValue(), left + 11 + i * BAR_SPACING, top, resources[i].getTextColor());
- }
- return true;
- }
+ int configAnchorNum = switch (i) {
+ case 0 -> SkyblockerConfig.get().general.bars.barpositions.healthBarPosition.toInt();
+ case 1 -> SkyblockerConfig.get().general.bars.barpositions.manaBarPosition.toInt();
+ case 2 -> SkyblockerConfig.get().general.bars.barpositions.defenceBarPosition.toInt();
+ case 3 -> SkyblockerConfig.get().general.bars.barpositions.experienceBarPosition.toInt();
+ default -> 0;
+ };
- private void renderText(MatrixStack matrices, int value, int left, int top, int color) {
- TextRenderer textRenderer = client.textRenderer;
- String text = Integer.toString(value);
- int x = left + (33 - textRenderer.getWidth(text)) / 2;
- int y = top - 3;
-
- // for i in [-1, 1]
- for (int i = -1; i < 2; i += 2) {
- textRenderer.draw(matrices, text, (float) (x + i), (float) y, 0);
- textRenderer.draw(matrices, text, (float) x, (float) (y + i), 0);
+ if (bars[i].anchorNum != configAnchorNum)
+ moveBar(i, configAnchorNum);
}
- textRenderer.draw(matrices, text, (float) x, (float) y, color);
+ RenderSystem.setShaderTexture(0, BARS);
+ for (var bar : bars)
+ bar.draw(matrices);
+ for (var bar : bars)
+ bar.drawText(matrices);
+ return true;
}
- private static class Resource {
- static final int INNER_WIDTH = 31;
- private int value;
- private int fillLevel;
- private final int textColor;
+ public void moveBar(int bar, int location) {
+ // Set the bar to the new anchor
+ bars[bar].anchorNum = location;
- public Resource(int textColor) {
- this.value = 0;
- this.fillLevel = INNER_WIDTH;
- this.textColor = textColor;
- }
-
- public void setMax(int value, int max) {
- this.value = value;
- this.fillLevel = value * INNER_WIDTH / max;
+ // Count how many bars are in each location
+ int layer1Count = 0, layer2Count = 0, rightCount = 0;
+ for (int i = 0; i < 4; i++) {
+ switch (bars[i].anchorNum) {
+ case 0 -> layer1Count++;
+ case 1 -> layer2Count++;
+ case 2 -> rightCount++;
+ }
}
- public void setFillLevel(int value, double fillLevel) {
- this.value = value;
- this.fillLevel = (int) (INNER_WIDTH * fillLevel);
+ // Set the bars width and offsetX according to their anchor and how many bars are on that layer
+ int adjustedLayer1Count = 0, adjustedLayer2Count = 0, adjustedRightCount = 0;
+ for (int i = 0; i < 4; i++) {
+ switch (bars[i].anchorNum) {
+ case 0 -> {
+ bars[i].bar_width = (172 - ((layer1Count - 1) * 11)) / layer1Count;
+ bars[i].offsetX = adjustedLayer1Count * (bars[i].bar_width + 11 + (layer1Count == 3 ? 0 : 1));
+ adjustedLayer1Count++;
+ }
+ case 1 -> {
+ bars[i].bar_width = (172 - ((layer2Count - 1) * 11)) / layer2Count;
+ bars[i].offsetX = adjustedLayer2Count * (bars[i].bar_width + 11 + (layer2Count == 3 ? 0 : 1));
+ adjustedLayer2Count++;
+ }
+ case 2 -> {
+ bars[i].bar_width = 50;
+ bars[i].offsetX = adjustedRightCount * (50 + 11);
+ adjustedRightCount++;
+ }
+ }
}
+ }
- public int getValue() {
- return value;
+ private class StatusBar {
+ public final int[] fill;
+ public int offsetX;
+ private final int v;
+ private final int text_color;
+ public int anchorNum;
+ public int bar_width;
+ public Object text;
+
+ private StatusBar(int i, int textColor, int fillNum) {
+ this.v = i * 9;
+ this.text_color = textColor;
+ this.fill = new int[fillNum];
+ this.fill[0] = 100;
+ this.anchorNum = 0;
+ this.text = "";
+ }
+
+ public void update(StatusBarTracker.Resource resource) {
+ int max = resource.max();
+ int val = resource.value();
+ this.fill[0] = fill(val, max);
+ this.fill[1] = fill(resource.overflow(), max);
+ this.text = val;
+ }
+
+ public void draw(MatrixStack matrices) {
+ // Dont draw if anchorNum is outside of range
+ if (anchorNum < 0 || anchorNum > 2) return;
+
+ // Draw the icon for the bar
+ drawTexture(matrices, anchorsX[anchorNum] + offsetX, anchorsY[anchorNum], 0, v, 9, 9);
+
+ // Draw the background for the bar
+ drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10, anchorsY[anchorNum], 10, v, 2, 9);
+ for (int i = 2; i < bar_width - 2; i++)
+ drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + i, anchorsY[anchorNum], 12, v, 1, 9);
+ drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + bar_width - 2, anchorsY[anchorNum], 41, v, 2, 9);
+
+ // Draw the filled part of the bar
+ for (int i = 0; i < fill.length; i++) {
+ for (int j = (bar_width - 3); j >= 0; j--) {
+ if ( Math.max((j * 100)/(bar_width - 3), 1) > fill[i]) continue;
+ drawTexture(matrices, anchorsX[anchorNum] + offsetX + 11 + j, anchorsY[anchorNum], ((j == 0 || j == bar_width - 3) ? 43 : 44) + i * 31, v, 1, 9);
+ }
+ }
}
- public int getFillCount() {
- return fillLevel / INNER_WIDTH;
- }
+ public void drawText(MatrixStack matrices) {
+ // Dont draw if anchorNum is outside of range
+ if (anchorNum < 0 || anchorNum > 2) return;
- public int getFillLevel() {
- return fillLevel % INNER_WIDTH;
- }
+ TextRenderer textRenderer = client.textRenderer;
+ String text = this.text.toString();
+ int x = anchorsX[anchorNum] + this.offsetX + 11 + (bar_width - textRenderer.getWidth(text)) / 2;
+ int y = anchorsY[anchorNum] - 3;
- public int getTextColor() {
- return textColor;
+ final int[] offsets = new int[]{-1, 1};
+ for (int i : offsets) {
+ textRenderer.draw(matrices, text, (float) (x + i), (float) y, 0);
+ textRenderer.draw(matrices, text, (float) x, (float) (y + i), 0);
+ }
+ textRenderer.draw(matrices, text, (float) x, (float) y, text_color);
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/StatusBarTracker.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/StatusBarTracker.java
new file mode 100644
index 00000000..0111f75a
--- /dev/null
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/StatusBarTracker.java
@@ -0,0 +1,110 @@
+package me.xmrvizzy.skyblocker.skyblock;
+
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.network.ClientPlayerEntity;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class StatusBarTracker {
+ private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](\\d+)/(\\d+)❤(?:(\\+§c\\d+. *)| *)");
+ private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+)§a❈ Defense *");
+ private static final Pattern MANA_USE = Pattern.compile("§b-\\d+ Mana \\(§\\S+(?:\\s\\S+)* *");
+ private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+)/(\\d+)✎ (?:Mana|§3(\\d+)ʬ) *");
+
+ private Resource health = new Resource(100, 100, 0);
+ private Resource mana = new Resource(100, 100, 0);
+ private int defense = 0;
+
+ public Resource getHealth() {
+ return this.health;
+ }
+
+ public Resource getMana() {
+ return this.mana;
+ }
+
+ public int getDefense() {
+ return this.defense;
+ }
+
+ private int parseInt(Matcher m, int group) {
+ return Integer.parseInt(m.group(group));
+ }
+
+ private void updateMana(Matcher m) {
+ int value = parseInt(m, 1);
+ int max = parseInt(m, 2);
+ int overflow = m.group(3) == null ? 0 : parseInt(m, 3);
+ this.mana = new Resource(value, max, overflow);
+ }
+
+ private void updateHealth(Matcher m) {
+ int value = parseInt(m, 1);
+ int max = parseInt(m, 2);
+ int overflow = 0;
+ ClientPlayerEntity player = null;
+ try {
+ player = MinecraftClient.getInstance().player;
+ }
+ // Is triggered by tests. Couldn't come up with a better solution.
+ catch (NullPointerException ignored) {
+ }
+ if (player != null) {
+ int hp = (int) (player.getHealth() * max / player.getMaxHealth());
+ overflow = value - hp;
+ value = hp;
+ } else if (value > max) {
+ overflow = value - max;
+ value = max;
+ }
+ if (overflow > max)
+ overflow = max;
+ this.health = new Resource(value, max, overflow);
+ }
+
+ private String reset(String str, Matcher m) {
+ str = str.substring(m.end());
+ m.reset(str);
+ return str;
+ }
+
+ public String update(String actionBar, boolean filterManaUse) {
+ var sb = new StringBuilder();
+ Matcher matcher = STATUS_HEALTH.matcher(actionBar);
+ if (!matcher.lookingAt())
+ return actionBar;
+ updateHealth(matcher);
+ if (matcher.group(3) != null) {
+ sb.append("§c❤");
+ sb.append(matcher.group(3));
+ }
+ actionBar = reset(actionBar, matcher);
+ if (matcher.usePattern(MANA_STATUS).lookingAt()) {
+ defense = 0;
+ updateMana(matcher);
+ actionBar = reset(actionBar, matcher);
+ } else {
+ if (matcher.usePattern(DEFENSE_STATUS).lookingAt()) {
+ defense = parseInt(matcher, 1);
+ actionBar = reset(actionBar, matcher);
+ } else if (filterManaUse && matcher.usePattern(MANA_USE).lookingAt()) {
+ actionBar = reset(actionBar, matcher);
+ }
+ if (matcher.usePattern(MANA_STATUS).find()) {
+ updateMana(matcher);
+ matcher.appendReplacement(sb, "");
+ }
+ }
+ matcher.appendTail(sb);
+ String res = sb.toString().trim();
+ return res.isEmpty() ? null : res;
+ }
+
+ public record Resource(
+ int value,
+ int max,
+ int overflow
+ ) {
+ }
+}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/OldLever.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/OldLever.java
index fc26f913..c836e4f3 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/OldLever.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/OldLever.java
@@ -14,7 +14,7 @@ public class OldLever {
protected static final VoxelShape WEST_SHAPE;
public static VoxelShape getShape(WallMountLocation wallMountLocation, Direction direction) {
- if (!SkyblockerConfig.get().locations.dungeons.oldLevers)
+ if (!SkyblockerConfig.get().general.hitbox.oldLeverHitbox)
return null;
if (wallMountLocation == WallMountLocation.FLOOR) {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
index c3da7c18..3af82b6e 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
@@ -16,7 +16,7 @@ public class Reparty extends ChatPatternListener {
private static final MinecraftClient client = MinecraftClient.getInstance();
private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance();
public static final Pattern PLAYER = Pattern.compile(" ([a-zA-Z0-9_]{2,16}) ●");
- private static final int BASE_DELAY = 20;
+ private static final int BASE_DELAY = 10;
private String[] players;
private int playersSoFar;
@@ -24,12 +24,11 @@ public class Reparty extends ChatPatternListener {
public Reparty() {
super("^(?:You are not currently in a party\\.|Party (?:Membe|Moderato)rs(?: \\(([0-9]+)\\)|:( .*)))$");
- repartying = false;
+ this.repartying = false;
ClientCommandManager.DISPATCHER.register(
ClientCommandManager.literal("rp").executes(context -> {
- if (!Utils.isOnSkyblock || repartying || client.player == null)
- return 0;
- repartying = true;
+ if (!Utils.isOnSkyblock || this.repartying || client.player == null) return 0;
+ this.repartying = true;
client.player.sendChatMessage("/p list");
return 0;
})
@@ -38,52 +37,42 @@ public class Reparty extends ChatPatternListener {
@Override
public ChatFilterResult state() {
- return repartying ? ChatFilterResult.FILTER : ChatFilterResult.PASS;
+ return this.repartying ? ChatFilterResult.FILTER : ChatFilterResult.PASS;
}
@Override
public boolean onMatch(Text message, Matcher matcher) {
if (matcher.group(1) != null) {
- playersSoFar = 0;
- players = new String[Integer.parseInt(matcher.group(1)) - 1];
+ this.playersSoFar = 0;
+ this.players = new String[Integer.parseInt(matcher.group(1)) - 1];
} else if (matcher.group(2) != null) {
Matcher m = PLAYER.matcher(matcher.group(2));
while (m.find()) {
- players[playersSoFar++] = m.group(1);
+ this.players[playersSoFar++] = m.group(1);
}
} else {
- repartying = false;
+ this.repartying = false;
return false;
}
- if (playersSoFar == players.length)
- reparty();
+ if (this.playersSoFar == this.players.length) reparty();
return false;
}
private void reparty() {
ClientPlayerEntity playerEntity = client.player;
if (playerEntity == null) {
- repartying = false;
+ this.repartying = false;
return;
}
sendCommand(playerEntity, "/p disband", 1);
- StringBuilder sb = new StringBuilder();
- int invites = (players.length - 1) / 5 + 1;
- for (int i = 0; i < invites; i++) {
- sb.setLength(0);
- sb.append("/p invite");
- for (int j = 0; j < 5 && i * 5 + j < players.length; j++) {
- sb.append(' ');
- sb.append(players[i * 5 + j]);
- }
- sendCommand(playerEntity, sb.toString(), i + 2);
+ for (int i = 0; i < this.players.length; ++i) {
+ String command = "/p invite " + this.players[i];
+ sendCommand(playerEntity, command, i + 2);
}
- skyblocker.scheduler.schedule(() -> repartying = false, invites + 2);
+ skyblocker.scheduler.schedule(() -> this.repartying = false, this.players.length + 2);
}
private void sendCommand(ClientPlayerEntity player, String command, int delay) {
- skyblocker.scheduler.schedule(() ->
- player.sendChatMessage(command), delay * BASE_DELAY
- );
+ skyblocker.scheduler.schedule(() -> player.sendChatMessage(command), delay * BASE_DELAY);
}
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
index 673797d4..7f22f59b 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
@@ -60,16 +60,15 @@ public class Trivia extends ChatPatternListener {
answers.put("What is the status of Thorn?", new String[]{"Shaman Necromancer"});
answers.put("What is the status of Livid?", new String[]{"Master Necromancer"});
answers.put("What is the status of Sadan?", new String[]{"Necromancer Lord"});
- answers.put("What is the status of Maxor?", new String[]{"Young Wither"});
- answers.put("What is the status of Goldor?", new String[]{"Wither Soldier"});
- answers.put("What is the status of Storm?", new String[]{"Elementalist"});
- answers.put("What is the status of Necron?", new String[]{"Wither Lord"});
- answers.put("How many total Fairy Souls are there?", new String[]{"227 Fairy Souls"});
+ answers.put("What is the status of Maxor?", new String[]{"The Wither Lords"});
+ answers.put("What is the status of Goldor?", new String[]{"The Wither Lords"});
+ answers.put("What is the status of Storm?", new String[]{"The Wither Lords"});
+ answers.put("What is the status of Necron?", new String[]{"The Wither Lords"});
+ answers.put("How many total Fairy Souls are there?", new String[]{"238 Fairy Souls"});
answers.put("How many Fairy Souls are there in Spider's Den?", new String[]{"19 Fairy Souls"});
answers.put("How many Fairy Souls are there in The End?", new String[]{"12 Fairy Souls"});
- answers.put("How many Fairy Souls are there in The Barn?", new String[]{"7 Fairy Souls"});
- answers.put("How many Fairy Souls are there in Mushroom Desert?", new String[]{"13 Fairy Souls"});
- answers.put("How many Fairy Souls are there in Blazing Fortress?", new String[]{"19 Fairy Souls"});
+ answers.put("How many Fairy Souls are there in The Farming Islands?", new String[]{"20 Fairy Souls"});
+ answers.put("How many Fairy Souls are there in Crimson Isle?", new String[]{"29 Fairy Souls"});
answers.put("How many Fairy Souls are there in The Park?", new String[]{"11 Fairy Souls"});
answers.put("How many Fairy Souls are there in Jerry's Workshop?", new String[]{"5 Fairy Souls"});
answers.put("How many Fairy Souls are there in Hub?", new String[]{"79 Fairy Souls"});
@@ -83,7 +82,7 @@ public class Trivia extends ChatPatternListener {
answers.put("What is the name of the person that upgrades pets?", new String[]{"Kat"});
answers.put("What is the name o