diff options
Diffstat (limited to 'src/main')
4 files changed, 96 insertions, 11 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java index 32f0b7e3..a207ddc7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java @@ -563,7 +563,9 @@ public class DungeonManager { if (room != null && currentRoom != room) { if (currentRoom != null && room.getType() == Room.Type.FAIRY) { currentRoom.nextRoom = room; - room.keyFound = currentRoom.keyFound; + if (currentRoom.keyFound) { + room.keyFound = true; + } } currentRoom = room; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java index b12bba62..8e0073f7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java @@ -3,12 +3,12 @@ package de.hysky.skyblocker.skyblock.dungeon.secrets; import com.google.gson.JsonObject; import it.unimi.dsi.fastutil.ints.IntSortedSet; import it.unimi.dsi.fastutil.objects.ObjectIntPair; -import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.MapColor; import net.minecraft.item.map.MapIcon; import net.minecraft.item.map.MapState; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; @@ -286,14 +286,13 @@ public class DungeonMapUtils { } private static boolean hasWitherOrBloodDoor(World world, Vector2ic pos, BlockPos.Mutable doorPos) { - return isWitherOrBloodDoor(world, doorPos.set(pos.x() - 2, 69, pos.y() + 14)) || - isWitherOrBloodDoor(world, doorPos.set(pos.x() + 14, 69, pos.y() - 2)) || - isWitherOrBloodDoor(world, doorPos.set(pos.x() + 14, 69, pos.y() + 30)) || - isWitherOrBloodDoor(world, doorPos.set(pos.x() + 30, 69, pos.y() + 14)); + return isWitherOrBloodDoor(world, doorPos.set(pos.x() + 1, 72, pos.y() + 17)) || + isWitherOrBloodDoor(world, doorPos.set(pos.x() + 17, 72, pos.y() + 1)) || + isWitherOrBloodDoor(world, doorPos.set(pos.x() + 17, 72, pos.y() + 33)) || + isWitherOrBloodDoor(world, doorPos.set(pos.x() + 33, 72, pos.y() + 17)); } - private static boolean isWitherOrBloodDoor(World world, BlockPos pos) { - BlockState state = world.getBlockState(pos); - return state.isOf(Blocks.COAL_BLOCK) || state.isOf(Blocks.RED_TERRACOTTA); + private static boolean isWitherOrBloodDoor(World world, BlockPos.Mutable pos) { + return world.getStatesInBox(Box.enclosing(pos, pos.move(-3, -3, -3))).allMatch(state -> state.isOf(Blocks.COAL_BLOCK) || state.isOf(Blocks.RED_TERRACOTTA)); } } 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 5f0d2c3c..e37da755 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 @@ -67,6 +67,11 @@ public abstract class Widget { this.addComponent(new IcoTextComponent(ico, txt)); } + public final void addSimpleIcoText(ItemStack ico, String string, Formatting fmt, String content) { + Text txt = Widget.simpleEntryText(content, string, fmt); + this.addComponent(new IcoTextComponent(ico, txt)); + } + /** * Calculate the size of this widget. * <b>Must be called before returning from the widget constructor and after all diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java index 1d11c2a6..fe23f19a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java @@ -1,17 +1,47 @@ package de.hysky.skyblocker.skyblock.tabhud.widget.hud; +import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud; 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; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.Locale; + // this widget shows the status of the king's commissions. // (dwarven mines and crystal hollows) // USE ONLY WITH THE DWARVEN HUD! public class HudPowderWidget extends Widget { + /** + * American number format instance + */ + private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); + /** + * current value of Mithril Powder + */ + private static int mithrilPowder = 0; + /** + * current value of Gemstone Powder + */ + private static int gemstonePowder = 0; + /** + * the difference between the previous and current value of Mithril Powder + */ + private static int mithrilPowderDiff = 0; + /** + * the difference between the previous and current value of Gemstone Powder + */ + private static int gemstonePowderDiff = 0; + /** + * The initial value of the timer for the difference update delay countdown. + */ + private static long startTime = System.currentTimeMillis(); + private static final MutableText TITLE = Text.literal("Powders").formatted(Formatting.DARK_AQUA, Formatting.BOLD); @@ -30,11 +60,60 @@ public class HudPowderWidget extends Widget { super(TITLE, Formatting.DARK_AQUA.getColorValue()); } + /** + * Converts a string with a number and commas between digits to an integer value. + * + * @param str a string with a number and commas between digits + * @return integer value + */ + private static int parsePowder(String str) { + try { + return NUMBER_FORMAT.parse(str).intValue(); + } catch (ParseException e) { + return 0; + } + } + + /** + * Converts Powder and difference values to a string and adds commas to the digits of the numbers. + * + * @param powder the value of Mithril or Gemstone Powder + * @param diff the difference between the previous and current value of Mithril or Gemstone Powder + * @return formatted string + */ + private static String formatPowderString(int powder, int diff) { + if (diff == 0) return NUMBER_FORMAT.format(powder); + return NUMBER_FORMAT.format(powder) + (diff > 0 ? " (+" : " (") + NUMBER_FORMAT.format(diff) + ")"; + } + + /** + * Updates Powders and difference values when Powder values change or every 2 seconds. + */ + private static void updatePowders() { + long elapsedTime = System.currentTimeMillis() - startTime; + + int newMithrilPowder = parsePowder(DwarvenHud.mithrilPowder); + int newGemstonePowder = parsePowder(DwarvenHud.gemStonePowder); + + if (newMithrilPowder != mithrilPowder || newGemstonePowder != gemstonePowder || elapsedTime > 2000) { + startTime = System.currentTimeMillis(); + + mithrilPowderDiff = newMithrilPowder - mithrilPowder; + gemstonePowderDiff = newGemstonePowder - gemstonePowder; + + mithrilPowder = newMithrilPowder; + gemstonePowder = newGemstonePowder; + } + } @Override public void updateContent() { - this.addSimpleIcoText(Ico.MITHRIL, "Mithril:", Formatting.AQUA, 46); - this.addSimpleIcoText(Ico.AMETHYST_SHARD, "Gemstone:", Formatting.DARK_PURPLE, 47); + updatePowders(); + String mithrilPowderString = formatPowderString(mithrilPowder, mithrilPowderDiff); + String gemstonePowderString = formatPowderString(gemstonePowder, gemstonePowderDiff); + + this.addSimpleIcoText(Ico.MITHRIL, "Mithril: ", Formatting.AQUA, mithrilPowderString); + this.addSimpleIcoText(Ico.AMETHYST_SHARD, "Gemstone: ", Formatting.DARK_PURPLE, gemstonePowderString); } } |