Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Nav Refactor and Clean Up, 2 Extra Tabs, Config Version 3, Config Data Fixer Refactor, Debug Dump Hovered Item Tool #643

Merged
merged 10 commits into from
May 20, 2024
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class SkyblockerMod implements ClientModInitializer {
public static final String VERSION = SKYBLOCKER_MOD.getMetadata().getVersion().getFriendlyString();
public static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir().resolve(NAMESPACE);
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final Gson GSON_COMPACT = new GsonBuilder().create();
private static SkyblockerMod INSTANCE;
public final ContainerSolverManager containerSolverManager = new ContainerSolverManager();
public final StatusBarTracker statusBarTracker = new StatusBarTracker();
Expand Down Expand Up @@ -119,7 +120,6 @@ public void onInitializeClient() {
EnderNodes.init();
OrderedWaypoints.init();
BackpackPreview.init();
QuickNav.init();
ItemCooldowns.init();
TabHud.init();
DwarvenHud.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.nio.file.Path;

public class SkyblockerConfigManager {
public static final int CONFIG_VERSION = 2;
public static final int CONFIG_VERSION = 3;
private static final Path CONFIG_FILE = FabricLoader.getInstance().getConfigDir().resolve("skyblocker.json");
private static final ConfigClassHandler<SkyblockerConfig> HANDLER = ConfigClassHandler.createBuilder(SkyblockerConfig.class)
.serializer(config -> GsonConfigSerializerBuilder.create(config)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.hysky.skyblocker.config.configs;

import dev.isxander.yacl3.config.v2.api.SerialEntry;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

public class QuickNavigationConfig {
@SerialEntry
Expand All @@ -24,63 +27,56 @@ public class QuickNavigationConfig {
* " \\([12]\\/2\\)" : match on the page either " (1/2)" or " (2/2)"
*/
@SerialEntry
public QuickNavItem button4 = new QuickNavItem(true,
new ItemData("leather_chestplate", 1, "[minecraft:dyed_color={rgb:8991416}]"), "Wardrobe \\([12]/2\\)",
"/wardrobe");
public QuickNavItem button4 = new QuickNavItem(true, new ItemData("leather_chestplate", 1, "[minecraft:dyed_color={rgb:8991416}]"), "Wardrobe \\([12]/2\\)", "/wardrobe");

@SerialEntry
public QuickNavItem button5 = new QuickNavItem(true, new ItemData("player_head", 1,
"[minecraft:profile={id:[I;-2081424676,-57521078,-2073572414,158072763],name:\"\",properties:[{name:\"textures\",value:\"ewogICJ0aW1lc3RhbXAiIDogMTU5MTMxMDU4NTYwOSwKICAicHJvZmlsZUlkIiA6ICI0MWQzYWJjMmQ3NDk0MDBjOTA5MGQ1NDM0ZDAzODMxYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNZWdha2xvb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBhMDc3ZTI0OGQxNDI3NzJlYTgwMDg2NGY4YzU3OGI5ZDM2ODg1YjI5ZGFmODM2YjY0YTcwNjg4MmI2ZWMxMCIKICAgIH0KICB9Cn0=\"}]}]"),
"Sack of Sacks", "/sacks");
public QuickNavItem button5 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={id:[I;-2081424676,-57521078,-2073572414,158072763],name:\"\",properties:[{name:\"textures\",value:\"ewogICJ0aW1lc3RhbXAiIDogMTU5MTMxMDU4NTYwOSwKICAicHJvZmlsZUlkIiA6ICI0MWQzYWJjMmQ3NDk0MDBjOTA5MGQ1NDM0ZDAzODMxYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNZWdha2xvb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBhMDc3ZTI0OGQxNDI3NzJlYTgwMDg2NGY4YzU3OGI5ZDM2ODg1YjI5ZGFmODM2YjY0YTcwNjg4MmI2ZWMxMCIKICAgIH0KICB9Cn0=\"}]}]"), "Sack of Sacks", "/sacks");

@SerialEntry
public QuickNavItem button6 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={name:\"5da6bec64bd942bc\",id:[I;1571208902,1272529596,-1566400349,-679283814],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTYxYTkxOGMwYzQ5YmE4ZDA1M2U1MjJjYjkxYWJjNzQ2ODkzNjdiNGQ4YWEwNmJmYzFiYTkxNTQ3MzA5ODVmZiJ9fX0=\"}]}]"), "Accessory Bag(?: \\(\\d/\\d\\))?", "/accessories");

/* REGEX Explanation
* "(?:Rift )?" : optional match on the non-capturing group "Rift "
* "Storage" : simple match on letters
* "(?: \\([12]\\/2\\))?" : optional match on the non-capturing group " (1/2)" or " (2/2)"
*/
@SerialEntry
public QuickNavItem button6 = new QuickNavItem(true, new ItemData("ender_chest"),
"(?:Rift )?Storage(?: \\(1/2\\))?", "/storage");
public QuickNavItem button7 = new QuickNavItem(true, new ItemData("ender_chest"), "(?:Rift )?Storage(?: \\(\\d/\\d\\))?", "/storage");

@SerialEntry
public QuickNavItem button7 = new QuickNavItem(true, new ItemData("player_head", 1,
"[minecraft:profile={id:[I;-300151517,-631415889,-1193921967,-1821784279],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=\"}]}]"),
"none", "/hub");
public QuickNavItem button8 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={name:\"421a8ef40eff47f4\",id:[I;1109036788,251611124,-2126904485,-130621758],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0=\"}]}]"), "", "/is");

@SerialEntry
public QuickNavItem button8 = new QuickNavItem(true, new ItemData("player_head", 1,
"[minecraft:profile={id:[I;1605800870,415127827,-1236127084,15358548],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}]"),
"none", "/warp dungeon_hub");
public QuickNavItem button9 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={name:\"e30e30d02878417c\",id:[I;-485609264,678969724,-1929747597,-718202427],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjQ4ODBkMmMxZTdiODZlODc1MjJlMjA4ODI2NTZmNDViYWZkNDJmOTQ5MzJiMmM1ZTBkNmVjYWE0OTBjYjRjIn19fQ==\"}]}]"), "", "/warp garden");

@SerialEntry
public QuickNavItem button9 = new QuickNavItem(true, new ItemData("player_head", 1,
"[minecraft:profile={id:[I;-562285948,532499670,-1705302742,775653035],name:\"\",properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjVkZjU1NTkyNjQzMGQ1ZDc1YWRlZDIxZGQ5NjE5Yjc2YzViN2NhMmM3ZjU0MDE0NDA1MjNkNTNhOGJjZmFhYiJ9fX0=\"}]}]"),
"Visit prtl", "/visit prtl");
public QuickNavItem button10 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={id:[I;-300151517,-631415889,-1193921967,-1821784279],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=\"}]}]"), "none", "/hub");

@SerialEntry
public QuickNavItem button10 = new QuickNavItem(true, new ItemData("enchanting_table"), "Enchant Item",
"/etable");
public QuickNavItem button11 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={id:[I;1605800870,415127827,-1236127084,15358548],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}]"), "none", "/warp dungeon_hub");

@SerialEntry
public QuickNavItem button12 = new QuickNavItem(true, new ItemData("gold_block"), "", "/ah");

@SerialEntry
public QuickNavItem button11 = new QuickNavItem(true, new ItemData("anvil"), "Anvil", "/anvil");
public QuickNavItem button13 = new QuickNavItem(true, new ItemData("player_head", 1, "[minecraft:profile={id:[I;-562285948,532499670,-1705302742,775653035],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlMmRjZGE0MWVjM2FmZjhhZjUwZjI3MmVjMmUwNmE4ZjUwOWUwZjgwN2YyMzU1YTFmNWEzM2MxYjY2ZTliNCJ9fX0=\"}]}]"), "Bazaar .*", "/bz");

@SerialEntry
public QuickNavItem button12 = new QuickNavItem(true, new ItemData("crafting_table"), "Craft Item", "/craft");
public QuickNavItem button14 = new QuickNavItem(true, new ItemData("crafting_table"), "Craft Item", "/craft");

public static class QuickNavItem {
public QuickNavItem(Boolean render, ItemData itemData, String uiTitle, String clickEvent) {
this.render = render;
this.item = itemData;
this.itemData = itemData;
this.clickEvent = clickEvent;
this.uiTitle = uiTitle;
}

@SerialEntry
public Boolean render;
public boolean render;

@SerialEntry
public ItemData item;
public ItemData itemData;

@SerialEntry
public String uiTitle;
Expand All @@ -90,20 +86,26 @@ public QuickNavItem(Boolean render, ItemData itemData, String uiTitle, String cl
}

public static class ItemData {
public ItemData(String id, int count, String components) {
this.id = id;
this.count = count;
this.components = components;
public ItemData(String item) {
this(item, 1, "[]");
}

public ItemData(String id) {
this.id = id;
this.count = 1;
this.components = "[]";
public ItemData(String item, int count, String components) {
this(Registries.ITEM.get(new Identifier(item)), count, components);
}

public ItemData(Item item) {
this(item, 1, "[]");
}

public ItemData(Item item, int count, String components) {
this.item = item;
this.count = count;
this.components = components;
}

@SerialEntry
public String id;
public Item item;

@SerialEntry
public int count;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.hysky.skyblocker.config.datafixer;

import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;

public abstract class ConfigDataFix extends DataFix {
public ConfigDataFix(Schema outputSchema, boolean changesType) {
super(outputSchema, changesType);
}

protected <T> Dynamic<T> fixVersion(Dynamic<T> dynamic) {
return dynamic.set("version", dynamic.createInt(DataFixUtils.getVersion(getVersionKey())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ public static void apply(Path configDir, Path backupDir) {
}

public static JsonObject apply(JsonObject oldConfig) {
return apply(oldConfig, SkyblockerConfigManager.CONFIG_VERSION);
}

public static JsonObject apply(JsonObject oldConfig, int newVersion) {
long start = System.currentTimeMillis();

JsonObject newConfig = build().update(CONFIG_TYPE, new Dynamic<>(JsonOps.INSTANCE, oldConfig), JsonHelper.getInt(oldConfig, "version").orElse(1), SkyblockerConfigManager.CONFIG_VERSION).getValue().getAsJsonObject();
JsonObject newConfig = build().update(CONFIG_TYPE, new Dynamic<>(JsonOps.INSTANCE, oldConfig), JsonHelper.getInt(oldConfig, "version").orElse(1), newVersion).getValue().getAsJsonObject();

long end = System.currentTimeMillis();
LOGGER.info("[Skyblocker Config Data Fixer] Applied datafixers in {} ms!", end - start);
Expand All @@ -62,6 +66,8 @@ private static DataFixer build() {
builder.addSchema(1, ConfigSchema::new);
Schema schema2 = builder.addSchema(2, Schema::new);
builder.addFixer(new ConfigFix1(schema2, true));
Schema schema3 = builder.addSchema(3, Schema::new);
builder.addFixer(new ConfigFix2QuickNav(schema3, true));

return builder.buildUnoptimized();
}
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix1.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.hysky.skyblocker.config.datafixer;

import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.logging.LogUtils;
Expand All @@ -14,7 +12,7 @@

import java.util.Locale;

public class ConfigFix1 extends DataFix {
public class ConfigFix1 extends ConfigDataFix {
public ConfigFix1(Schema outputSchema, boolean changesType) {
super(outputSchema, changesType);
}
Expand All @@ -32,10 +30,6 @@ private <T> Dynamic<T> fix(Dynamic<T> dynamic) {
return fixMisc(fixQuickNav(fixChat(fixSlayers(fixOtherLocations(fixFarming(fixMining(fixCrimsonIsle(fixDungeons(fixHelpers(fixUIAndVisuals(fixGeneral(fixVersion(dynamic)))))))))))));
}

private <T> Dynamic<T> fixVersion(Dynamic<T> dynamic) {
return dynamic.set("version", dynamic.createInt(DataFixUtils.getVersion(getVersionKey())));
}

private static <T> Dynamic<T> fixGeneral(Dynamic<T> dynamic) {
return dynamic.update("general", general -> general.update("itemTooltip", itemTooltip -> itemTooltip.setFieldIfPresent("dungeonQuality", general.get("dungeonQuality").result())).remove("dungeonQuality"));
}
Expand Down Expand Up @@ -180,19 +174,9 @@ private static <T> Dynamic<T> fixChat(Dynamic<T> dynamic) {
}

private static <T> Dynamic<T> fixQuickNav(Dynamic<T> dynamic) {
return dynamic.update("quickNav", quickNav -> quickNav
.update("button1", ConfigFix1::fixQuickNavButton)
.update("button2", ConfigFix1::fixQuickNavButton)
.update("button3", ConfigFix1::fixQuickNavButton)
.update("button4", ConfigFix1::fixQuickNavButton)
.update("button5", ConfigFix1::fixQuickNavButton)
.update("button6", ConfigFix1::fixQuickNavButton)
.update("button7", ConfigFix1::fixQuickNavButton)
.update("button8", ConfigFix1::fixQuickNavButton)
.update("button9", ConfigFix1::fixQuickNavButton)
.update("button10", ConfigFix1::fixQuickNavButton)
.update("button11", ConfigFix1::fixQuickNavButton)
.update("button12", ConfigFix1::fixQuickNavButton));
return dynamic.update("quickNav", quickNav -> quickNav.updateMapValues(button ->
button.getFirst().asString().getOrThrow().startsWith("button") ? button.mapSecond(ConfigFix1::fixQuickNavButton) : button
));
}

private static <T> Dynamic<T> fixQuickNavButton(Dynamic<T> button) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.hysky.skyblocker.config.datafixer;

import com.mojang.datafixers.DSL;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import net.minecraft.util.Identifier;

public class ConfigFix2QuickNav extends ConfigDataFix {
public ConfigFix2QuickNav(Schema outputSchema, boolean changesType) {
super(outputSchema, changesType);
}

@Override
protected TypeRewriteRule makeRule() {
return fixTypeEverywhereTyped(
"ConfigFix2QuickNav",
getInputSchema().getType(ConfigDataFixer.CONFIG_TYPE),
typed -> typed.update(DSL.remainderFinder(), this::fix)
);
}

private <T> Dynamic<T> fix(Dynamic<T> dynamic) {
return fixVersion(dynamic).update("quickNav", quickNav -> quickNav
.renameField("button12", "button13")
.renameField("button11", "button12")
.renameField("button10", "button11")
.renameField("button9", "button10")
.renameField("button8", "button9")
.renameField("button7", "button8")
.updateMapValues(button -> button.getFirst().asString().getOrThrow().startsWith("button") ? button.mapSecond(this::fixButton) : button)
);
}

private <T> Dynamic<T> fixButton(Dynamic<T> button) {
return button.renameAndFixField("item", "itemData", itemData -> itemData.renameAndFixField("id", "item", id -> id.createString(new Identifier(id.asString().getOrThrow()).toString())));
}
}
27 changes: 21 additions & 6 deletions src/main/java/de/hysky/skyblocker/debug/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.serialization.JsonOps;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.text.Text;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
import org.lwjgl.glfw.GLFW;

import java.util.List;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class Debug {
private static final boolean DEBUG_ENABLED = Boolean.parseBoolean(System.getProperty("skyblocker.debug", "false"));

Expand All @@ -26,6 +32,10 @@ public static boolean debugEnabled() {
return DEBUG_ENABLED || FabricLoader.getInstance().isDevelopmentEnvironment();
}

public static boolean shouldShowInvisibleArmorStands() {
return showInvisibleArmorStands;
}

public static void init() {
if (debugEnabled()) {
SnapshotDebug.init();
Expand All @@ -35,6 +45,15 @@ public static void init() {
.then(toggleShowingInvisibleArmorStands())
.then(dumpArmorStandHeadTextures())
)));
ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (screen instanceof HandledScreen<?> handledScreen) {
ScreenKeyboardEvents.afterKeyPress(screen).register((_screen, key, scancode, modifier) -> {
if (key == GLFW.GLFW_KEY_U && client.player != null) {
client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, ((HandledScreenAccessor) handledScreen).getFocusedSlot().getStack()))));
}
});
}
});
}
}

Expand Down Expand Up @@ -73,8 +92,4 @@ private static LiteralArgumentBuilder<FabricClientCommandSource> dumpArmorStandH
return Command.SINGLE_SUCCESS;
});
}

public static boolean shouldShowInvisibleArmorStands() {
return showInvisibleArmorStands;
}
}
Loading