diff options
| author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-10-15 15:09:50 -0400 |
|---|---|---|
| committer | viciscat <51047087+viciscat@users.noreply.github.com> | 2024-12-12 18:22:21 +0100 |
| commit | 64ed1d5a376a63a37186589d8324bb97dcddcaf0 (patch) | |
| tree | b287f4366a316cc5929719df0ae53d957937aea6 /src/main/java/de | |
| parent | 0cb8e3dc05c43d3e1a64765a77179657c1e38373 (diff) | |
| download | Skyblocker-64ed1d5a376a63a37186589d8324bb97dcddcaf0.tar.gz Skyblocker-64ed1d5a376a63a37186589d8324bb97dcddcaf0.tar.bz2 Skyblocker-64ed1d5a376a63a37186589d8324bb97dcddcaf0.zip | |
Apply suggestions
* Refactor locations
* Refactor comparator
* Add Javadoc for ASM injection points
Diffstat (limited to 'src/main/java/de')
5 files changed, 13 insertions, 31 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java index 3bf5028a..e142b701 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java @@ -22,11 +22,13 @@ import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerListener; import net.minecraft.text.Text; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -278,8 +280,7 @@ public class WidgetsConfigurationScreen extends Screen implements ScreenHandlerL } public DropdownWidget<Location> createLocationDropdown(Consumer<Location> onLocationChanged) { - List<Location> locations = new ArrayList<>(List.of(Location.hudLocations())); - locations.remove(Location.DUNGEON); // there's already a tab for that + List<Location> locations = Arrays.asList(ArrayUtils.removeElements(Location.values(), Location.UNKNOWN, Location.DUNGEON)); // there's already a tab for dungeons return new DropdownWidget<>(client, 0, 0, 50, 50, locations, location -> { setCurrentLocation(location); onLocationChanged.accept(location); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java index f379ca8d..b831d449 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java @@ -3,7 +3,6 @@ package de.hysky.skyblocker.skyblock.tabhud.config; import de.hysky.skyblocker.skyblock.tabhud.config.entries.WidgetsListEntry; import de.hysky.skyblocker.skyblock.tabhud.config.entries.slot.WidgetsListSlotEntry; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.IntComparators; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Element; @@ -11,10 +10,7 @@ import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; public class WidgetsElementList extends ElementListWidget<WidgetsListEntry> { static final Identifier MOVE_UP_HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("transferable_list/move_up_highlighted"); @@ -59,7 +55,7 @@ public class WidgetsElementList extends ElementListWidget<WidgetsListEntry> { ArrayList<Int2ObjectMap.Entry<WidgetsListSlotEntry>> entries = new ArrayList<>(parent.getEntries()); clearEntries(); entries.stream() - .sorted((a, b) -> IntComparators.NATURAL_COMPARATOR.compare(a.getIntKey(), b.getIntKey())) + .sorted(Comparator.comparingInt(Int2ObjectMap.Entry::getIntKey)) .map(Map.Entry::getValue) .forEach(this::addEntry); if (!parent.getCustomWidgetEntries().isEmpty() && parent.shouldShowCustomWidgetEntries()) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/preview/PreviewTab.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/preview/PreviewTab.java index 1b1f4ffd..8f9bbce2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/preview/PreviewTab.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/preview/PreviewTab.java @@ -357,8 +357,8 @@ public class PreviewTab implements Tab { if (this.previewWidget.selectedWidget == null) return; PositionRule toCopy = ScreenMaster.getScreenBuilder(getCurrentLocation()).getPositionRule(this.previewWidget.selectedWidget.getInternalID()); if (toCopy == null && !(this.previewWidget.selectedWidget instanceof TabHudWidget)) return; - for (Location value : Location.hudLocations()) { - if (value == getCurrentLocation() || value == Location.DUNGEON) continue; + for (Location value : Location.values()) { + if (value == getCurrentLocation() || value == Location.DUNGEON || value == Location.UNKNOWN) continue; ScreenMaster.getScreenBuilder(value).setPositionRule( this.previewWidget.selectedWidget.getInternalID(), toCopy diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java index 8764f74e..7e5011d5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java @@ -172,10 +172,15 @@ public class ScreenMaster { /** - * Filled at compile item with ASM. Do not fill this. + * Filled at compile item with ASM. + * Do not fill this method or change the signature unless you know what you're doing */ private static void instantiateWidgets() {} + /** + * Called by the ASM generated code to add a widget instance to the map. + * Do not change the signature unless you know what you're doing. + */ public static void addWidgetInstance(HudWidget widget) { HudWidget put = widgetInstances.put(widget.getInternalID(), widget); if (widget instanceof TabHudWidget tabHudWidget) { diff --git a/src/main/java/de/hysky/skyblocker/utils/Location.java b/src/main/java/de/hysky/skyblocker/utils/Location.java index 90a5264a..225df308 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Location.java +++ b/src/main/java/de/hysky/skyblocker/utils/Location.java @@ -1,13 +1,9 @@ package de.hysky.skyblocker.utils; -import org.apache.commons.lang3.ArrayUtils; - import com.mojang.serialization.Codec; import net.minecraft.util.StringIdentifiable; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; /** * All Skyblock locations @@ -135,20 +131,4 @@ public enum Location implements StringIdentifiable { public static Location from(String id) { return Arrays.stream(Location.values()).filter(loc -> id.equals(loc.id())).findFirst().orElse(UNKNOWN); } - - public static Location[] locationsWithout(Location... locations) { - return ArrayUtils.removeElements(values(), locations); - } - - private static Location[] hudLocations = null; - - /** - * @return All the locations available for the hud - */ - public static Location[] hudLocations() { - if (hudLocations == null) { - hudLocations = locationsWithout(UNKNOWN); - } - return hudLocations; - } } |
