diff options
Diffstat (limited to 'src')
43 files changed, 709 insertions, 369 deletions
diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 2987f493..ebb85b36 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -8,8 +8,8 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; 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.*; @@ -22,6 +22,7 @@ import de.hysky.skyblocker.skyblock.dwarven.CrystalsLocationsManager; 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; @@ -108,8 +109,10 @@ public class SkyblockerMod implements ClientModInitializer { BackpackPreview.init(); QuickNav.init(); ItemCooldowns.init(); + TabHud.init(); DwarvenHud.init(); CrystalsHud.init(); + FarmingHud.init(); CrystalsLocationsManager.init(); ChatMessageListener.init(); Shortcuts.init(); @@ -118,7 +121,6 @@ public class SkyblockerMod implements ClientModInitializer { 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 c33e2f54..07109b46 100644 --- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java @@ -2,82 +2,141 @@ package de.hysky.skyblocker.config; 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. + * <p> + * 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<Widget> 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<Widget> 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<Widget> 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<IntIntMutablePair> 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<IntIntMutablePair> 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. * <p> * 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<Widget> widgets); } diff --git a/src/main/java/de/hysky/skyblocker/config/ImageRepoLoader.java b/src/main/java/de/hysky/skyblocker/config/ImageRepoLoader.java index 0591cd96..584b79e7 100644 --- a/src/main/java/de/hysky/skyblocker/config/ImageRepoLoader.java +++ b/src/main/java/de/hysky/skyblocker/config/ImageRepoLoader.java @@ -56,7 +56,7 @@ public class ImageRepoLoader { //Delete all directories to clear potentially now unused/old files //TODO change this to only delete periodically? - deleteDirectories(); + if (Files.exists(REPO_DIRECTORY)) deleteDirectories(); try (ZipInputStream zis = new ZipInputStream(in)) { ZipEntry entry; diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 4626003d..a3e710c1 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -267,6 +267,9 @@ public class SkyblockerConfig { public int tabHudScale = 100; @SerialEntry + public boolean enableHudBackground = true; + + @SerialEntry public boolean plainPlayerNames = false; @SerialEntry @@ -945,9 +948,6 @@ public class SkyblockerConfig { public DwarvenHudStyle style = DwarvenHudStyle.SIMPLE; @SerialEntry - public boolean enableBackground = true; - - @SerialEntry public int x = 10; @SerialEntry @@ -1037,7 +1037,7 @@ public class SkyblockerConfig { public boolean noArrowPoisonWarning = true; @SerialEntry - public int arrowPoisonThreshold = 16; + public int arrowPoisonThreshold = 32; } public static class Rift { @@ -1063,9 +1063,6 @@ public class SkyblockerConfig { public boolean hudEnabled = true; @SerialEntry - public boolean enableBackground = true; - - @SerialEntry public boolean waypoint = true; @SerialEntry @@ -1090,12 +1087,26 @@ public class SkyblockerConfig { public static class Garden { @SerialEntry + public FarmingHud farmingHud = new FarmingHud(); + + @SerialEntry public boolean dicerTitlePrevent = true; @SerialEntry 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(); @@ -1106,10 +1117,13 @@ public class SkyblockerConfig { public static class EndermanSlayer { @SerialEntry - public boolean highlightNukekubiHeads = true; + public boolean enableYangGlyphsNotification = true; @SerialEntry public boolean highlightBeacons = true; + + @SerialEntry + public boolean highlightNukekubiHeads = true; } public static class VampireSlayer { @@ -1199,6 +1213,7 @@ public class SkyblockerConfig { @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 97b48bc4..4ae0fc35 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 class DwarvenMinesCategory { .text(Text.translatable("text.skyblocker.open")) .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new DwarvenHudConfigScreen(screen))) .build()) - .option(Option.<Boolean>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 afd688d8..23ce7bb6 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java @@ -107,6 +107,14 @@ public class GeneralCategory { .controller(opt -> IntegerSliderControllerBuilder.create(opt).range(10, 200).step(1)) .build()) .option(Option.<Boolean>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.<Boolean>createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames")) .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames.@Tooltip"))) .binding(defaults.general.tabHud.plainPlayerNames, 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 d97513f8..86ed3f6c 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.ConfigUtils; 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; @@ -91,13 +92,6 @@ public class LocationsCategory { .controller(ConfigUtils::createBooleanController) .build()) .option(Option.<Boolean>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.<Boolean>createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.waypoint")) .binding(defaults.locations.end.waypoint, () -> config.locations.end.waypoint, @@ -147,6 +141,18 @@ public class LocationsCategory { .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden")) .collapsed(false) .option(Option.<Boolean>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.<Boolean>createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.dicerTitlePrevent")) .binding(defaults.locations.garden.dicerTitlePrevent, () -> config.locations.garden.dicerTitlePrevent, @@ -154,7 +160,7 @@ public class LocationsCategory { .controller(ConfigUtils::createBooleanController) .build()) .option(Option.<Boolean>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/config/categories/SlayersCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/SlayersCategory.java index 19b30937..005bebab 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/SlayersCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/SlayersCategory.java @@ -22,10 +22,10 @@ public class SlayersCategory { .name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer")) .collapsed(true) .option(Option.<Boolean>createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads")) - .binding(defaults.slayer.endermanSlayer.highlightNukekubiHeads, - () -> config.slayer.endermanSlayer.highlightNukekubiHeads, - newValue -> config.slayer.endermanSlayer.highlightNukekubiHeads = newValue) + .name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.enableYangGlyphsNotification")) + .binding(defaults.slayer.endermanSlayer.enableYangGlyphsNotification, + () -> config.slayer.endermanSlayer.enableYangGlyphsNotification, + newValue -> config.slayer.endermanSlayer.enableYangGlyphsNotification = newValue) .controller(ConfigUtils::createBooleanController) .build()) .option(Option.<Boolean>createBuilder() @@ -35,6 +35,13 @@ public class SlayersCategory { newValue -> config.slayer.endermanSlayer.highlightBeacons = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads")) + .binding(defaults.slayer.endermanSlayer.highlightNukekubiHeads, + () -> config.slayer.endermanSlayer.highlightNukekubiHeads, + newValue -> config.slayer.endermanSlayer.highlightNukekubiHeads = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) //Vampire Slayer diff --git a/src/main/java/de/hysky/skyblocker/mixin/DataTrackerMixin.java b/src/main/java/de/hysky/skyblocker/mixin/DataTrackerMixin.java index 03786876..d9db5dae 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/DataTrackerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/DataTrackerMixin.java @@ -1,19 +1,50 @@ package de.hysky.skyblocker.mixin; +import com.llamalad7.mixinextras.sugar.Local; +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.mixin.accessor.EndermanEntityAccessor; +import de.hysky.skyblocker.skyblock.entity.MobGlow; +import de.hysky.skyblocker.utils.Utils; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.hysky.skyblocker.utils.Utils; -import net.minecraft.entity.data.DataTracker; +import java.util.Optional; @Mixin(DataTracker.class) -public class DataTrackerMixin { +public abstract class DataTrackerMixin { + @Shadow + @Final + private Entity trackedEntity; + + @SuppressWarnings("ConstantValue") + @Inject(method = "writeUpdatedEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/data/DataTracker;copyToFrom(Lnet/minecraft/entity/data/DataTracker$Entry;Lnet/minecraft/entity/data/DataTracker$SerializedEntry;)V")) + private <T> void skyblocker$onWriteUpdatedEntries(CallbackInfo ci, @Local DataTracker.Entry<T> entry, @Local DataTracker.SerializedEntry<T> serializedEntry) { + if (Utils.isInTheEnd() && SkyblockerConfigManager.get().slayer.endermanSlayer.enableYangGlyphsNotification && entry.getData() == EndermanEntityAccessor.getCARRIED_BLOCK() && entry.get() instanceof Optional<?> value && value.isPresent() && value.get() instanceof BlockState state && state.isOf(Blocks.BEACON) && ((Optional<?>) serializedEntry.value()).isEmpty()) { + MinecraftClient client = MinecraftClient.getInstance(); + if (MobGlow.getArmorStands(trackedEntity).stream().anyMatch(armorStand -> armorStand.getName().getString().contains(client.getSession().getUsername()))) { + client.inGameHud.setTitleTicks(5, 20, 10); + client.inGameHud.setTitle(Text.literal("Yang Glyph!").formatted(Formatting.RED)); + client.player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING.value(), 100f, 0.1f); + } + } + } - @Inject(method = "copyToFrom", at = @At(value = "NEW", target = "Ljava/lang/IllegalStateException;", shift = At.Shift.BEFORE), cancellable = true) - public void skyblocker$ignoreInvalidDataExceptions(CallbackInfo ci) { - //These exceptions cause annoying small lag spikes for some reason - if (Utils.isOnHypixel()) ci.cancel(); - } + @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) + @Inject(method = "copyToFrom", at = @At(value = "NEW", target = "Ljava/lang/IllegalStateException;"), cancellable = true) + public void skyblocker$ignoreInvalidDataExceptions(CallbackInfo ci) { + //These exceptions cause annoying small lag spikes for some reason + if (Utils.isOnHypixel()) ci.cancel(); + } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java b/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java index 5e3daf3c..75c516df 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java @@ -9,6 +9,7 @@ import de.hysky.skyblocker.skyblock.FancyStatusBars; import de.hysky.skyblocker.skyblock.dungeon.DungeonMap; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.DungeonScoreHUD; +import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.skyblock.item.HotbarSlotLock; import de.hysky.skyblocker.skyblock.item.ItemCooldowns; import de.hysky.skyblocker.skyblock.item.ItemProtection; @@ -91,7 +92,7 @@ public abstract class InGameHudMixin { ci.cancel(); if (Utils.isInDungeons() && DungeonScore.isDungeonStarted()) { - if (SkyblockerConfigManager.get().locations.dungeons.enableMap) DungeonMap.render(context.getMatrices()); + if (SkyblockerConfigManager.get().locations.dungeons.enableMap && !DungeonManager.isInBoss()) DungeonMap.render(context.getMatrices()); if (SkyblockerConfigManager.get().locations.dungeons.dungeonScore.enableScoreHUD) DungeonScoreHUD.render(context); } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/accessor/BeaconBlockEntityRendererInvoker.java b/src/main/java/de/hysky/skyblocker/mixin/accessor/BeaconBlockEntityRendererInvoker.java index 0b607fce..e470cdae 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/accessor/BeaconBlockEntityRendererInvoker.java +++ b/src/main/java/de/hysky/skyblocker/mixin/accessor/BeaconBlockEntityRendererInvoker.java @@ -11,6 +11,6 @@ public interface BeaconBlockEntityRendererInvoker { @SuppressWarnings("unused") @Invoker("renderBeam") static void renderBeam(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta, long worldTime, int yOffset, int maxY, float[] color) { - throw new IllegalStateException("Mixin invoker failed to apply."); + throw new UnsupportedOperationException(); } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/accessor/EndermanEntityAccessor.java b/src/main/java/de/hysky/skyblocker/mixin/accessor/EndermanEntityAccessor.java new file mode 100644 index 00000000..b7bcd95c --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/mixin/accessor/EndermanEntityAccessor.java @@ -0,0 +1,17 @@ +package de.hysky.skyblocker.mixin.accessor; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.data.TrackedData; +import net.minecraft.entity.mob.EndermanEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Optional; + +@Mixin(EndermanEntity.class) +public interface EndermanEntityAccessor { + @Accessor + static TrackedData<Optional<BlockState>> getCARRIED_BLOCK() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/de/hysky/skyblocker/mixin/accessor/MessageHandlerAccessor.java b/src/main/java/de/hysky/skyblocker/mixin/accessor/MessageHandlerAccessor.java new file mode 100644 index 00000000..6e5793e3 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/mixin/accessor/MessageHandlerAccessor.java @@ -0,0 +1,14 @@ +package de.hysky.skyblocker.mixin.accessor; + +import net.minecraft.client.network.message.MessageHandler; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.time.Instant; + +@Mixin(MessageHandler.class) +public interface MessageHandlerAccessor { + @Invoker + void invokeAddToChatLog(Text message, Instant timestamp); +} diff --git a/src/main/java/de/hysky/skyblocker/mixin/accessor/PlayerListHudAccessor.java b/src/main/java/de/hysky/skyblocker/mixin/accessor/PlayerListHudAccessor.java index d82c568f..c982249a 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/accessor/PlayerListHudAccessor.java +++ b/src/main/java/de/hysky/skyblocker/mixin/accessor/PlayerListHudAccessor.java @@ -9,9 +9,8 @@ import java.util.Comparator; @Mixin(PlayerListHud.class) public interface PlayerListHudAccessor { - @Accessor("ENTRY_ORDERING") static Comparator<PlayerListEntry> getOrdering() { - throw new AssertionError(); + throw new UnsupportedOperationException(); } } diff --git a/src/main/java/de/hysky/skyblocker/mixin/accessor/RecipeBookWidgetAccessor.java b/src/main/java/de/hysky/skyblocker/mixin/accessor/RecipeBookWidgetAccessor.java index aecdf9b7..30aad00c 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/accessor/RecipeBookWidgetAccessor.java +++ b/src/main/java/de/hysky/skyblocker/mixin/accessor/RecipeBookWidgetAccessor.java @@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.gen.Accessor; public interface RecipeBookWidgetAccessor { @Accessor String getSearchText(); + @Accessor TextFieldWidget getSearchField(); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java index 13115bee..2a103d13 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesHandler.java @@ -5,8 +5,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; - import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.mixin.accessor.MessageHandlerAccessor; import de.hysky.skyblocker.utils.Http; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; @@ -21,10 +21,10 @@ import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.time.Instant; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -53,16 +53,16 @@ public class ChatRulesHandler { private static void loadChatRules() { try (BufferedReader reader = Files.newBufferedReader(CHAT_RULE_FILE)) { Map<String, List<ChatRule>> chatRules = MAP_CODEC.parse(JsonOps.INSTANCE, JsonParser.parseReader(reader)).result().orElseThrow(); - LOGGER.info("[Sky: " + chatRules.toString()); - + LOGGER.info("[Skyblocker Chat Rules]: {}", chatRules); + chatRuleList.addAll(chatRules.get("rules")); - LOGGER.info("[Skyblocker] Loaded chat rules"); + LOGGER.info("[Skyblocker Chat Rules] Loaded chat rules"); } catch (NoSuchFileException e) { registerDefaultChatRules(); - LOGGER.warn("[Skyblocker] chat rule file not found, using default rules. This is normal when using for the first time."); + LOGGER.warn("[Skyblocker Chat Rules] chat rules file not found, using default rules. This is normal when using for the first time."); } catch (Exception e) { - LOGGER.error("[Skyblocker] Failed to load shortcuts file", e); + LOGGER.error("[Skyblocker Chat Rules] Failed to load chat rules file", e); } } @@ -92,7 +92,7 @@ public class ChatRulesHandler { locations.put(entry.getValue().getAsString().replace(" ", "").toLowerCase(), entry.getKey()); } } catch (Exception e) { - LOGGER.error("[Skyblocker] Failed to load locations!", e); + LOGGER.error("[Skyblocker Chat Rules] Failed to load locations!", e); } } @@ -101,9 +101,9 @@ public class ChatRulesHandler { chatRuleJson.add("rules", ChatRule.LIST_CODEC.encodeStart(JsonOps.INSTANCE, chatRuleList).result().orElseThrow()); try (BufferedWriter writer = Files.newBufferedWriter(CHAT_RULE_FILE)) { SkyblockerMod.GSON.toJson(chatRuleJson, writer); - LOGGER.info("[Skyblocker] Saved chat rules file"); + LOGGER.info("[Skyblocker Chat Rules] Saved chat rules file"); } catch (Exception e) { - LOGGER.error("[Skyblocker] Failed to save chat rules file", e); + LOGGER.error("[Skyblocker Chat Rules] Failed to save chat rules file", e); } } @@ -136,9 +136,12 @@ public class ChatRulesHandler { CLIENT.player.sendMessage(newMessage, true); } - //hide message + //show replacement message in chat + //bypass MessageHandler#onGameMessage to avoid activating chat rules again if (!rule.getHideMessage() && CLIENT.player != null) { - CLIENT.player.sendMessage(newMessage, false); + CLIENT.inGameHud.getChatHud().addMessage(newMessage); + ((MessageHandlerAccessor) CLIENT.getMessageHandler()).invokeAddToChatLog(newMessage, Instant.now()); + CLIENT.getNarratorManager().narrateSystemMessage(newMessage); } //play sound diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMap.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMap.java index 293d301f..f2986ec0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMap.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMap.java @@ -4,48 +4,65 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.scheduler.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.MapRenderer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.FilledMapItem; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.item.map.MapState; -import net.minecraft.nbt.NbtCompound; -import org.apache.commons.lang3.StringUtils; public class DungeonMap { + private static final int DEFAULT_MAP_ID = 1024; + private static Integer cachedMapId = null; + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("hud") + .then(ClientCommandManager.literal("dungeon") + .executes(Scheduler.queueOpenScreenCommand(DungeonMapConfigScreen::new)) + ) + ) + )); + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> reset()); + } + public static void render(MatrixStack matrices) { MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null || client.world == null) return; - ItemStack item = client.player.getInventory().main.get(8); - NbtCompound tag = item.getNbt(); - - if (tag != null && tag.contains("map")) { - String tag2 = tag.asString(); - tag2 = StringUtils.substringBetween(tag2, "map:", "}"); - int mapid = Integer.parseInt(tag2); - VertexConsumerProvider.Immediate vertices = client.getBufferBuilders().getEffectVertexConsumers(); - MapRenderer map = client.gameRenderer.getMapRenderer(); - MapState state = FilledMapItem.getMapState(mapid, client.world); - float scaling = SkyblockerConfigManager.get().locations.dungeons.mapScaling; - int x = SkyblockerConfigManager.get().locations.dungeons.mapX; - int y = SkyblockerConfigManager.get().locations.dungeons.mapY; - - if (state == null) return; - matrices.push(); - matrices.translate(x, y, 0); - matrices.scale(scaling, scaling, 0f); - map.draw(matrices, vertices, mapid, state, false, 15728880); - vertices.draw(); - matrices.pop(); - } + + int mapId = getMapId(client.player.getInventory().main.get(8)); + + MapState state = FilledMapItem.getMapState(mapId, client.world); + if (state == null) return; + + int x = SkyblockerConfigManager.get().locations.dungeons.mapX; + int y = SkyblockerConfigManager.get().locations.dungeons.mapY; + float scaling = SkyblockerConfigManager.get().locations.dungeons.mapScaling; + VertexConsumerProvider.Immediate vertices = client.getBufferBuilders().getEffectVertexConsumers(); + MapRenderer mapRenderer = client.gameRenderer.getMapRenderer(); + + matrices.push(); + matrices.translate(x, y, 0); + matrices.scale(scaling, scaling, 0f); + mapRenderer.draw(matrices, vertices, mapId, state, false, LightmapTextureManager.MAX_LIGHT_COORDINATE); + vertices.draw(); + matrices.pop(); } - public static void init() { //Todo: consider renaming the command to a more general name since it'll also have dungeon score and maybe other stuff in the future - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") - .then(ClientCommandManager.literal("hud") - .then(ClientCommandManager.literal("dungeonmap") - .executes(Scheduler.queueOpenScreenCommand(DungeonMapConfigScreen::new)))))); + public static int getMapId(ItemStack stack) { + if (stack.isOf(Items.FILLED_MAP)) { + @SuppressWarnings("DataFlowIssue") + int mapId = FilledMapItem.getMapId(stack); + cachedMapId = mapId; + return mapId; + } else return cachedMapId != null ? cachedMapId : DEFAULT_MAP_ID; + } + + private static void reset() { + cachedMapId = null; } -}
\ No newline at end of file +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/CreeperBeams.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/CreeperBeams.java index 73cd99c8..419ce85c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/CreeperBeams.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/CreeperBeams.java @@ -32,6 +32,7 @@ public class CreeperBeams extends DungeonPuzzle { DyeColor.LIME.getColorComponents(), DyeColor.YELLOW.getColorComponents(), DyeColor.MAGENTA.getColorComponents(), + DyeColor.PINK.getColorComponents(), }; private static final float[] GREEN_COLOR_COMPONENTS = DyeColor.GREEN.getColorComponents(); @@ -155,7 +156,7 @@ public class CreeperBeams extends DungeonPuzzle { ArrayList<Beam> result = new ArrayList<>(); allLines.sort(Comparator.comparingDouble(ObjectDoublePair::rightDouble)); - while (result.size() < 4 && !allLines.isEmpty()) { + while (result.size() < 5 && !allLines.isEmpty()) { Beam solution = allLines.get(0).left(); result.add(solution); @@ -165,7 +166,7 @@ public class CreeperBeams extends DungeonPuzzle { allLines.removeIf(beam -> solution.containsComponentOf(beam.left())); } - if (result.size() != 4) { + if (result.size() < 5) { LOGGER.error("Not enough solutions found. This is bad..."); } 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 ea06b7dc..d5d57e70 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 @@ -15,6 +15,7 @@ import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.debug.Debug; +import de.hysky.skyblocker.skyblock.dungeon.DungeonMap; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Tickable; import de.hysky.skyblocker.utils.Utils; @@ -526,11 +527,7 @@ public class DungeonManager { physicalEntrancePos = DungeonMapUtils.getPhysicalRoomPos(playerPos); currentRoom = newRoom(Room.Type.ENTRANCE, physicalEntrancePos); } - ItemStack stack = client.player.getInventory().main.get(8); - if (!stack.isOf(Items.FILLED_MAP)) { - return; - } - MapState map = FilledMapItem.getMapState(FilledMapItem.getMapId(stack), client.world); + MapState map = FilledMapItem.getMapState(DungeonMap.getMapId(client.player.getInventory().main.get(8)), client.world); if (map == null) { return; } 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(); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/end/BeaconHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/end/BeaconHighlighter.java index 6c89a07c..a2298ecf 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/end/BeaconHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/end/BeaconHighlighter.java @@ -48,7 +48,7 @@ public class BeaconHighlighter { private static void render(WorldRenderContext context) { if (Utils.isInTheEnd() && SkyblockerConfigManager.get().slayer.endermanSlayer.highlightBeacons) { for (BlockPos pos : beaconPositions) { - RenderHelper.renderFilled(context, pos, RED_COLOR_COMPONENTS, 0.5f, false); + RenderHelper.renderFilled(context, pos, RED_COLOR_COMPONENTS, 0.5f, true); } } } 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 2502afd7..659fc79f 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 @@ package de.hysky.skyblocker.skyblock.end; 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<IntIntMutablePair> 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<Widget> 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 1db27769..10672bde 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 class TheEnd { 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/entity/MobGlow.java b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java index 90513a4b..85b41bd2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java @@ -44,7 +44,7 @@ public class MobGlow { // Regular Mobs if (!(entity instanceof ArmorStandEntity)) { - List<ArmorStandEntity> armorStands = getArmorStands(entity.getWorld(), box); + List<ArmorStandEntity> armorStands = getArmorStands(entity); if (!armorStands.isEmpty() && armorStands.get(0).getName().getString().contains("✯")) return SkyblockerConfigManager.get().locations.dungeons.starredMobGlow; @@ -79,7 +79,11 @@ public class MobGlow { return false; } - private static List<ArmorStandEntity> getArmorStands(World world, Box box) { + public static List<ArmorStandEntity> getArmorStands(Entity entity) { + return getArmorStands(entity.getWorld(), entity.getBoundingBox()); + } + + public static List<ArmorStandEntity> getArmorStands(World world, Box box) { return world.getEntitiesByClass(ArmorStandEntity.class, box.expand(0, 2, 0), EntityPredicates.NOT_MOUNTED); } 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 00000000..95c72241 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java @@ -0,0 +1,123 @@ +package de.hysky.skyblocker.skyblock.garden; + +import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.config.SkyblockerConfigManager; +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; +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; + +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); + private static final Pattern COUNTER = Pattern.compile("Counter: (?<count>[\\d,]+) .+"); + private static final Pattern FARMING_XP = Pattern.compile("§3\\+(?<xp>\\d+.?\\d*) Farming \\((?<percent>\\d+.?\\d*)%\\)"); + private static final Deque<IntLongPair> counter = new ArrayDeque<>(); + private static final LongPriorityQueue blockBreaks = new LongArrayFIFOQueue(); + private static final Queue<FloatLongPair> farmingXp = new ArrayDeque<>(); + private static float farmingXpPercentProgress; + + public static void init() { + HudRenderCallback.EVENT.register((context, tickDelta) -> { + 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); + } + } + + FarmingHudWidget.INSTANCE.update(); + FarmingHudWidget.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); + } + } + } + }); + 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() { + 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/FarmingHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java new file mode 100644 index 00000000..5384d47a --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java @@ -0,0 +1,30 @@ +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 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, FarmingHudWidget.INSTANCE); + } + + @SuppressWarnings("SuspiciousNameCombination") + @Override + protected List<IntIntMutablePair> 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<Widget> 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/garden/FarmingHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java new file mode 100644 index 00000000..6ddb0e05 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java @@ -0,0 +1,67 @@ +package de.hysky.skyblocker.skyblock.garden; + +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; +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 FarmingHudWidget extends Widget { + private static final MutableText TITLE = Text.literal("Farming").formatted(Formatting.YELLOW, Formatting.BOLD); + private static final Map<String, ItemStack> 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 FarmingHudWidget INSTANCE = new FarmingHudWidget(); + private final MinecraftClient client = MinecraftClient.getInstance(); + + public FarmingHudWidget() { + super(TITLE, Formatting.YELLOW.getColorValue()); + setX(SkyblockerConfigManager.get().locations.garden.farmingHud.x); + setY(SkyblockerConfigManager.get().locations.garden.farmingHud.y); + update(); + } + + @SuppressWarnings("DataFlowIssue") + @Override + public void updateContent() { + 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.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(); + 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/skyblock/garden/VisitorHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java index 92e7e258..bde8b3ea 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; 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 @@ -111,7 +112,7 @@ public class VisitorHelper { 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<String> visitorMap = itemMap.getOrDefault(visitorName, new Object2IntOpenHashMap<>()); visitorMap.putIfAbsent(itemName, amount); itemMap.putIfAbsent(visitorName, visitorMap); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java b/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java index 773f1808..ae908245 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java @@ -1,26 +1,10 @@ package de.hysky.skyblocker.skyblock.item; -import java.io.ByteArrayInputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.lang.reflect.Type; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import java.util.Base64; -import java.util.Map; -import java.util.concurrent.CompletableFuture; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; import com.mojang.util.UndashedUuid; - import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.utils.Http; import de.hysky.skyblocker.utils.Http.ApiResponse; @@ -29,12 +13,21 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.minecraft.client.MinecraftClient; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtIo; -import net.minecraft.nbt.NbtList; -import net.minecraft.nbt.NbtTagSizeTracker; -import net.minecraft.util.Util; +import net.minecraft.nbt.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.util.Base64; +import java.util.Map; +import java.util.concurrent.CompletableFuture; public class MuseumItemCache { private static final Logger LOGGER = LoggerFactory.getLogger(MuseumItemCache.class); @@ -142,9 +135,8 @@ public class MuseumItemCache { public static void tick(String profileId) { if (loaded.isDone()) { String uuid = UndashedUuid.toString(MinecraftClient.getInstance().getSession().getUuidOrNull()); - Object2ObjectOpenHashMap<String, ProfileMuseumData> playerData = MUSEUM_ITEM_CACHE.computeIfAbsent(uuid, uuid1 -> Util.make(new Object2ObjectOpenHashMap<>(), map -> { - map.put(profileId, ProfileMuseumData.EMPTY); - })); + Object2ObjectOpenHashMap<String, ProfileMuseumData> playerData = MUSEUM_ITEM_CACHE.computeIfAbsent(uuid, _uuid -> new Object2ObjectOpenHashMap<>()); + playerData.putIfAbsent(profileId, ProfileMuseumData.EMPTY); if (playerData.get(profileId).stale()) updateData4ProfileMember(uuid, profileId); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java b/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java index aa55a4e3..8d0c30b8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java @@ -71,7 +71,7 @@ public class EnigmaSouls { try (BufferedReader reader = Files.newBufferedReader(FOUND_SOULS_FILE)) { for (Map.Entry<String, JsonElement> profile : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { for (JsonElement foundSoul : profile.getValue().getAsJsonArray().asList()) { - SOUL_WAYPOINTS.get(PosUtils.parsePosString(foundSoul.getAsString())).setFound(); + SOUL_WAYPOINTS.get(PosUtils.parsePosString(foundSoul.getAsString())).setFound(profile.getKey()); } } } catch (NoSuchFileException ignored) { 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 96ab35d5..4872435b 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 9cff3d32..9aa4a50e 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.Formatting; 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 class CameraPositionWidget extends Widget { 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/EmptyWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java new file mode 100644 index 00000000..4c9bcf7f --- /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 e37da755..01a8720b 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 @@ import net.minecraft.util.Formatting; public abstract class Widget { private final ArrayList<Component> 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 @@ public abstract class Widget { 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 abstract class Widget { return this.y; } - public final int getX() { - return this.x; - } - public final void setY(int y) { this.y = y; } @@ -113,10 +113,27 @@ public abstract class Widget { 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/waypoint/FairySouls.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/FairySouls.java index f0e94770..7f826b23 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/FairySouls.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/FairySouls.java @@ -52,7 +52,7 @@ public class FairySouls { @SuppressWarnings("UnusedReturnValue") public static CompletableFuture<Void> runAsyncAfterFairySoulsLoad(Runnable runnable) { if (fairySoulsLoaded == null) { - LOGGER.error("Fairy Souls have not being initialized yet! Please ensure the Fairy Souls module is initialized before modules calling this method in SkyblockerMod#onInitializeClient. This error can be safely ignore in a test environment."); + LOGGER.error("[Skyblocker] Fairy Souls have not being initialized yet! Please ensure the Fairy Souls module is initialized before modules calling this method in SkyblockerMod#onInitializeClient. This error can be safely ignore in a test environment."); return CompletableFuture.completedFuture(null); } return fairySoulsLoaded.thenRunAsync(runnable); @@ -79,10 +79,9 @@ public class FairySouls { try (BufferedReader reader = Files.newBufferedReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json"))) { for (Map.Entry<String, JsonElement> foundFairiesForProfileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { for (Map.Entry<String, JsonElement> foundFairiesForLocationJson : foundFairiesForProfileJson.getValue().getAsJsonObject().asMap().entrySet()) { - String profile = foundFairiesForLocationJson.getKey(); - Map<BlockPos, ProfileAwareWaypoint> fairiesForLocation = fairySouls.get(profile); + Map<BlockPos, ProfileAwareWaypoint> fairiesForLocation = fairySouls.get(foundFairiesForLocationJson.getKey()); for (JsonElement foundFairy : foundFairiesForLocationJson.getValue().getAsJsonArray().asList()) { - fairiesForLocation.get(PosUtils.parsePosString(foundFairy.getAsString())).setFound(profile); + fairiesForLocation.get(PosUtils.parsePosString(foundFairy.getAsString())).setFound(foundFairiesForProfileJson.getKey()); } } } diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index 880ebe76..70a8c241 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.ZoneId; 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 class ItemUtils { 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<Text> getNbtTooltips(ItemStack item) { NbtCompound displayNbt = item.getSubNbt("display"); if (displayNbt == null || !displayNbt.contains("Lore", NbtElement.LIST_TYPE)) { diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 08d0b167..3e3bc4af 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -37,6 +37,8 @@ public class Utils { private static final String ALTERNATE_HYPIXEL_ADDRESS = System.getProperty("skyblocker.alternateHypixelAddress", ""); private static final String PROFILE_PREFIX = "Profile: "; + private static final String PROFILE_MESSAGE_PREFIX = "§aYou are playing on profile: §e"; + public static final String PROFILE_ID_PREFIX = "Profile ID: "; private static boolean isOnHypixel = false; private static boolean isOnSkyblock = false; private static boolean isInjected = false; @@ -424,10 +426,14 @@ public class Utils { return shouldFilter; } - if (isOnSkyblock && message.startsWith("Profile ID: ")) { - profileId = message.replace("Profile ID: ", ""); + if (isOnSkyblock) { + if (message.startsWith(PROFILE_MESSAGE_PREFIX)) { + profile = message.substring(PROFILE_MESSAGE_PREFIX.length()).split("§b")[0]; + } else if (message.startsWith(PROFILE_ID_PREFIX)) { + profileId = message.substring(PROFILE_ID_PREFIX.length()); - MuseumItemCache.tick(profileId); + MuseumItemCache.tick(profileId); + } } return true; diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 7bff321f..6b6c5f68 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", @@ -195,13 +196,16 @@ "text.autoconfig.skyblocker.option.locations.crimsonIsle.kuudra.noArrowPoisonWarning": "No Arrow Poison Warning", "text.autoconfig.skyblocker.option.locations.crimsonIsle.kuudra.noArrowPoisonWarning.@Tooltip": "Warns you when you pull out a bow and have no Toxic Arrow Poison in your inventory. Only works during the DPS phase.", "text.autoconfig.skyblocker.option.locations.crimsonIsle.kuudra.arrowPoisonThreshold": "Arrow Poison Warning Threshold", - "text.autoconfig.skyblocker.option.locations.crimsonIsle.kuudra.arrowPoisonThreshold.@Tooltip": "If the amount of Toxic Arrow Poison you have in your inventory is below the set threshold then you will receive a warning.", + "text.autoconfig.skyblocker.option.locations.crimsonIsle.kuudra.arrowPoisonThreshold.@Tooltip": "If the amount of Toxic Arrow Poison you have in your inventory is below the set threshold then you will receive a warning.\n\n16 is the absolute minimum.\nYou want 32 for smooth 'DPS' phase with prefire.", "text.autoconfig.skyblocker.option.locations.spidersDen": "Spider's Den", "text.autoconfig.skyblocker.option.locations.spidersDen.relics": "Hidden Relics Helper", "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", @@ -315,7 +319,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...", @@ -424,9 +427,10 @@ "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.amethyst": "Amethyst", "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.anvil": "Break", "text.autoconfig.skyblocker.category.slayer": "Slayers", - "text.autoconfig.skyblocker.option.slayer.endermanSlayer": "[Beta] Enderman Slayer", - "text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads": "Nukekubi Head Highlighting", + "text.autoconfig.skyblocker.option.slayer.endermanSlayer": "Enderman Slayer", + "text.autoconfig.skyblocker.option.slayer.endermanSlayer.enableYangGlyphsNotification": "Enable Yang Glyphs notification", "text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightBeacons": "Beacon Highlighting", + "text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads": "Nukekubi Head Highlighting", "text.autoconfig.skyblocker.option.slayer.vampireSlayer": "Vampire Slayer", "text.autoconfig.skyblocker.option.slayer.vampireSlayer.enableEffigyWaypoints": "Enable Effigy Waypoints", "text.autoconfig.skyblocker.option.slayer.vampireSlayer.compactEffigyWaypoints": "Compact Effigy Waypoints", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 461d5223..c5d05fed 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -41,6 +41,9 @@ "conflicts": { "immediatelyfast": "<=1.2.10+1.20.4" }, + "breaks": { + "forcecloseworldloadingscreen": "<=2.2.0" + }, "custom": { "modmenu": { "links": { diff --git a/src/main/resources/skyblocker.mixins.json b/src/main/resources/skyblocker.mixins.json index fd7364ce..cc08ced8 100644 --- a/src/main/resources/skyblocker.mixins.json +++ b/src/main/resources/skyblocker.mixins.json @@ -36,9 +36,11 @@ "YggdrasilServicesKeyInfoMixin", "accessor.BeaconBlockEntityRendererInvoker", "accessor.DrawContextInvoker", + "accessor.EndermanEntityAccessor", "accessor.FrustumInvoker", "accessor.HandledScreenAccessor", "accessor.ItemStackAccessor", + "accessor.MessageHandlerAccessor", "accessor.PlayerListHudAccessor", "accessor.RecipeBookWidgetAccessor", "accessor.ScreenAccessor", |