diff options
Diffstat (limited to 'src/main/java')
14 files changed, 268 insertions, 709 deletions
diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 77b1ec2a..0dc1b409 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -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(); @@ -119,7 +120,6 @@ public class SkyblockerMod implements ClientModInitializer { EnderNodes.init(); OrderedWaypoints.init(); BackpackPreview.init(); - QuickNav.init(); ItemCooldowns.init(); TabHud.init(); DwarvenHud.init(); diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java index 2876b48f..dd406b8a 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java @@ -26,7 +26,7 @@ import java.lang.StackWalker.Option; 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) diff --git a/src/main/java/de/hysky/skyblocker/config/categories/QuickNavigationCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/QuickNavigationCategory.java index 64c67417..98e5511c 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/QuickNavigationCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/QuickNavigationCategory.java @@ -2,16 +2,18 @@ package de.hysky.skyblocker.config.categories; import de.hysky.skyblocker.config.ConfigUtils; import de.hysky.skyblocker.config.SkyblockerConfig; +import de.hysky.skyblocker.config.configs.QuickNavigationConfig; import dev.isxander.yacl3.api.ConfigCategory; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder; +import dev.isxander.yacl3.api.controller.ItemControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; +import net.minecraft.item.Item; import net.minecraft.text.Text; public class QuickNavigationCategory { - public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig config) { return ConfigCategory.createBuilder() .name(Text.translatable("skyblocker.config.quickNav")) @@ -25,594 +27,71 @@ public class QuickNavigationCategory { .controller(ConfigUtils::createBooleanController) .build()) - //Button 1 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 1)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button1.render, - () -> config.quickNav.button1.render, - newValue -> config.quickNav.button1.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button1.item.id, - () -> config.quickNav.button1.item.id, - newValue -> config.quickNav.button1.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button1.item.count, - () -> config.quickNav.button1.item.count, - newValue -> config.quickNav.button1.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button1.item.components, - () -> config.quickNav.button1.item.components, - newValue -> config.quickNav.button1.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button1.uiTitle, - () -> config.quickNav.button1.uiTitle, - newValue -> config.quickNav.button1.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button1.clickEvent, - () -> config.quickNav.button1.clickEvent, - newValue -> config.quickNav.button1.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) - - //Button 2 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 2)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button2.render, - () -> config.quickNav.button2.render, - newValue -> config.quickNav.button2.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button2.item.id, - () -> config.quickNav.button2.item.id, - newValue -> config.quickNav.button2.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button2.item.count, - () -> config.quickNav.button2.item.count, - newValue -> config.quickNav.button2.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button2.item.components, - () -> config.quickNav.button2.item.components, - newValue -> config.quickNav.button2.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button2.uiTitle, - () -> config.quickNav.button2.uiTitle, - newValue -> config.quickNav.button2.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button2.clickEvent, - () -> config.quickNav.button2.clickEvent, - newValue -> config.quickNav.button2.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) - - //Button 3 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 3)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button3.render, - () -> config.quickNav.button3.render, - newValue -> config.quickNav.button3.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button3.item.id, - () -> config.quickNav.button3.item.id, - newValue -> config.quickNav.button3.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button3.item.count, - () -> config.quickNav.button3.item.count, - newValue -> config.quickNav.button3.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button3.item.components, - () -> config.quickNav.button3.item.components, - newValue -> config.quickNav.button3.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button3.uiTitle, - () -> config.quickNav.button3.uiTitle, - newValue -> config.quickNav.button3.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button3.clickEvent, - () -> config.quickNav.button3.clickEvent, - newValue -> config.quickNav.button3.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) - - //Button 4 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 4)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button4.render, - () -> config.quickNav.button4.render, - newValue -> config.quickNav.button4.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button4.item.id, - () -> config.quickNav.button4.item.id, - newValue -> config.quickNav.button4.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button4.item.count, - () -> config.quickNav.button4.item.count, - newValue -> config.quickNav.button4.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button4.item.components, - () -> config.quickNav.button4.item.components, - newValue -> config.quickNav.button4.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button4.uiTitle, - () -> config.quickNav.button4.uiTitle, - newValue -> config.quickNav.button4.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button4.clickEvent, - () -> config.quickNav.button4.clickEvent, - newValue -> config.quickNav.button4.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) - - //Button 5 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 5)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button5.render, - () -> config.quickNav.button5.render, - newValue -> config.quickNav.button5.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button5.item.id, - () -> config.quickNav.button5.item.id, - newValue -> config.quickNav.button5.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button5.item.count, - () -> config.quickNav.button5.item.count, - newValue -> config.quickNav.button5.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button5.item.components, - () -> config.quickNav.button5.item.components, - newValue -> config.quickNav.button5.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button5.uiTitle, - () -> config.quickNav.button5.uiTitle, - newValue -> config.quickNav.button5.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button5.clickEvent, - () -> config.quickNav.button5.clickEvent, - newValue -> config.quickNav.button5.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) - - //Button 6 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 6)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button6.render, - () -> config.quickNav.button6.render, - newValue -> config.quickNav.button6.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button6.item.id, - () -> config.quickNav.button6.item.id, - newValue -> config.quickNav.button6.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button6.item.count, - () -> config.quickNav.button6.item.count, - newValue -> config.quickNav.button6.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button6.item.components, - () -> config.quickNav.button6.item.components, - newValue -> config.quickNav.button6.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button6.uiTitle, - () -> config.quickNav.button6.uiTitle, - newValue -> config.quickNav.button6.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button6.clickEvent, - () -> config.quickNav.button6.clickEvent, - newValue -> config.quickNav.button6.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) - .build()) + //Buttons + .group(quickNavButton(defaults.quickNav.button1, config.quickNav.button1, 1)) + .group(quickNavButton(defaults.quickNav.button2, config.quickNav.button2, 2)) + .group(quickNavButton(defaults.quickNav.button3, config.quickNav.button3, 3)) + .group(quickNavButton(defaults.quickNav.button4, config.quickNav.button4, 4)) + .group(quickNavButton(defaults.quickNav.button5, config.quickNav.button5, 5)) + .group(quickNavButton(defaults.quickNav.button6, config.quickNav.button6, 6)) + .group(quickNavButton(defaults.quickNav.button7, config.quickNav.button7, 7)) + .group(quickNavButton(defaults.quickNav.button8, config.quickNav.button8, 8)) + .group(quickNavButton(defaults.quickNav.button9, config.quickNav.button9, 9)) + .group(quickNavButton(defaults.quickNav.button10, config.quickNav.button10, 10)) + .group(quickNavButton(defaults.quickNav.button11, config.quickNav.button11, 11)) + .group(quickNavButton(defaults.quickNav.button12, config.quickNav.button12, 12)) + .group(quickNavButton(defaults.quickNav.button13, config.quickNav.button13, 13)) + .group(quickNavButton(defaults.quickNav.button14, config.quickNav.button14, 14)) + .build(); + } - //Button 7 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 7)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button7.render, - () -> config.quickNav.button7.render, - newValue -> config.quickNav.button7.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button7.item.id, - () -> config.quickNav.button7.item.id, - newValue -> config.quickNav.button7.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button7.item.count, - () -> config.quickNav.button7.item.count, - newValue -> config.quickNav.button7.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button7.item.components, - () -> config.quickNav.button7.item.components, - newValue -> config.quickNav.button7.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button7.uiTitle, - () -> config.quickNav.button7.uiTitle, - newValue -> config.quickNav.button7.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button7.clickEvent, - () -> config.quickNav.button7.clickEvent, - newValue -> config.quickNav.button7.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + private static OptionGroup quickNavButton(QuickNavigationConfig.QuickNavItem defaultButton, QuickNavigationConfig.QuickNavItem button, int index) { + return OptionGroup.createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button", index)) + .collapsed(true) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.render")) + .binding(defaultButton.render, + () -> button.render, + newValue -> button.render = newValue) + .controller(ConfigUtils::createBooleanController) .build()) - - //Button 8 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 8)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button8.render, - () -> config.quickNav.button8.render, - newValue -> config.quickNav.button8.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button8.item.id, - () -> config.quickNav.button8.item.id, - newValue -> config.quickNav.button8.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button8.item.count, - () -> config.quickNav.button8.item.count, - newValue -> config.quickNav.button8.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button8.item.components, - () -> config.quickNav.button8.item.components, - newValue -> config.quickNav.button8.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button8.uiTitle, - () -> config.quickNav.button8.uiTitle, - newValue -> config.quickNav.button8.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button8.clickEvent, - () -> config.quickNav.button8.clickEvent, - newValue -> config.quickNav.button8.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + .option(Option.<Item>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) + .binding(defaultButton.itemData.item, + () -> button.itemData.item, + newValue -> button.itemData.item = newValue) + .controller(ItemControllerBuilder::create) .build()) - - //Button 9 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 9)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button9.render, - () -> config.quickNav.button9.render, - newValue -> config.quickNav.button9.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button9.item.id, - () -> config.quickNav.button9.item.id, - newValue -> config.quickNav.button9.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button9.item.count, - () -> config.quickNav.button9.item.count, - newValue -> config.quickNav.button9.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button9.item.components, - () -> config.quickNav.button9.item.components, - newValue -> config.quickNav.button9.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button9.uiTitle, - () -> config.quickNav.button9.uiTitle, - newValue -> config.quickNav.button9.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button9.clickEvent, - () -> config.quickNav.button9.clickEvent, - newValue -> config.quickNav.button9.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + .option(Option.<Integer>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) + .binding(defaultButton.itemData.count, + () -> button.itemData.count, + newValue -> button.itemData.count = newValue) + .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) .build()) - - //Button 10 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 10)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button10.render, - () -> config.quickNav.button10.render, - newValue -> config.quickNav.button10.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button10.item.id, - () -> config.quickNav.button10.item.id, - newValue -> config.quickNav.button10.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button10.item.count, - () -> config.quickNav.button10.item.count, - newValue -> config.quickNav.button10.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button10.item.components, - () -> config.quickNav.button10.item.components, - newValue -> config.quickNav.button10.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button10.uiTitle, - () -> config.quickNav.button10.uiTitle, - newValue -> config.quickNav.button10.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button10.clickEvent, - () -> config.quickNav.button10.clickEvent, - newValue -> config.quickNav.button10.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + .option(Option.<String>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) + .binding(defaultButton.itemData.components, + () -> button.itemData.components, + newValue -> button.itemData.components = newValue) + .controller(StringControllerBuilder::create) .build()) - - //Button 11 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 11)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button11.render, - () -> config.quickNav.button11.render, - newValue -> config.quickNav.button11.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button11.item.id, - () -> config.quickNav.button11.item.id, - newValue -> config.quickNav.button11.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button11.item.count, - () -> config.quickNav.button11.item.count, - newValue -> config.quickNav.button11.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button11.item.components, - () -> config.quickNav.button11.item.components, - newValue -> config.quickNav.button11.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button11.uiTitle, - () -> config.quickNav.button11.uiTitle, - newValue -> config.quickNav.button11.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button11.clickEvent, - () -> config.quickNav.button11.clickEvent, - newValue -> config.quickNav.button11.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + .option(Option.<String>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) + .binding(defaultButton.uiTitle, + () -> button.uiTitle, + newValue -> button.uiTitle = newValue) + .controller(StringControllerBuilder::create) .build()) - - //Button 12 - .group(OptionGroup.createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button", 12)) - .collapsed(true) - .option(Option.<Boolean>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.render")) - .binding(defaults.quickNav.button12.render, - () -> config.quickNav.button12.render, - newValue -> config.quickNav.button12.render = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.itemName")) - .binding(defaults.quickNav.button12.item.id, - () -> config.quickNav.button12.item.id, - newValue -> config.quickNav.button12.item.id = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<Integer>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.count")) - .binding(defaults.quickNav.button12.item.count, - () -> config.quickNav.button12.item.count, - newValue -> config.quickNav.button12.item.count = newValue) - .controller(opt -> IntegerFieldControllerBuilder.create(opt).range(1, 99)) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.item.components")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.item.components.@Tooltip"))) - .binding(defaults.quickNav.button12.item.components, - () -> config.quickNav.button12.item.components, - newValue -> config.quickNav.button12.item.components = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.uiTitle")) - .binding(defaults.quickNav.button12.uiTitle, - () -> config.quickNav.button12.uiTitle, - newValue -> config.quickNav.button12.uiTitle = newValue) - .controller(StringControllerBuilder::create) - .build()) - .option(Option.<String>createBuilder() - .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) - .binding(defaults.quickNav.button12.clickEvent, - () -> config.quickNav.button12.clickEvent, - newValue -> config.quickNav.button12.clickEvent = newValue) - .controller(StringControllerBuilder::create) - .build()) + .option(Option.<String>createBuilder() + .name(Text.translatable("skyblocker.config.quickNav.button.clickEvent")) + .binding(defaultButton.clickEvent, + () -> button.clickEvent, + newValue -> button.clickEvent = newValue) + .controller(StringControllerBuilder::create) .build()) - .build(); } } diff --git a/src/main/java/de/hysky/skyblocker/config/configs/QuickNavigationConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/QuickNavigationConfig.java index ba863e33..20a0c9cc 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/QuickNavigationConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/QuickNavigationConfig.java @@ -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 @@ -24,14 +27,13 @@ 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 " @@ -39,48 +41,42 @@ public class QuickNavigationConfig { * "(?: \\([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; @@ -90,20 +86,26 @@ public class QuickNavigationConfig { } 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; diff --git a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFix.java b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFix.java new file mode 100644 index 00000000..9ec0e2b8 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFix.java @@ -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()))); + } +} diff --git a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFixer.java b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFixer.java index 97261c76..f4e4aad1 100644 --- a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFixer.java +++ b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigDataFixer.java @@ -47,9 +47,13 @@ public class ConfigDataFixer { } 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); @@ -62,6 +66,8 @@ public class ConfigDataFixer { 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(); } diff --git a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix1.java b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix1.java index 405a2781..8eff09e7 100644 --- a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix1.java +++ b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix1.java @@ -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; @@ -14,7 +12,7 @@ import net.minecraft.nbt.StringNbtReader; import java.util.Locale; -public class ConfigFix1 extends DataFix { +public class ConfigFix1 extends ConfigDataFix { public ConfigFix1(Schema outputSchema, boolean changesType) { super(outputSchema, changesType); } @@ -32,10 +30,6 @@ public class ConfigFix1 extends DataFix { 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")); } @@ -180,19 +174,9 @@ public class ConfigFix1 extends DataFix { } 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) { diff --git a/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix2QuickNav.java b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix2QuickNav.java new file mode 100644 index 00000000..bd67b1b0 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/config/datafixer/ConfigFix2QuickNav.java @@ -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()))); + } +} diff --git a/src/main/java/de/hysky/skyblocker/debug/Debug.java b/src/main/java/de/hysky/skyblocker/debug/Debug.java index 8c883b30..d9ac668c 100644 --- a/src/main/java/de/hysky/skyblocker/debug/Debug.java +++ b/src/main/java/de/hysky/skyblocker/debug/Debug.java @@ -2,21 +2,27 @@ package de.hysky.skyblocker.debug; 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")); @@ -26,6 +32,10 @@ public class Debug { return DEBUG_ENABLED || FabricLoader.getInstance().isDevelopmentEnvironment(); } + public static boolean shouldShowInvisibleArmorStands() { + return showInvisibleArmorStands; + } + public static void init() { if (debugEnabled()) { SnapshotDebug.init(); @@ -35,6 +45,15 @@ public class Debug { .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())))); + } + }); + } + }); } } @@ -73,8 +92,4 @@ public class Debug { return Command.SINGLE_SUCCESS; }); } - - public static boolean shouldShowInvisibleArmorStands() { - return showInvisibleArmorStands; - } } diff --git a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java index dd91314a..f662be7c 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java @@ -14,6 +14,8 @@ import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds; import de.hysky.skyblocker.skyblock.item.WikiLookup; import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview; import de.hysky.skyblocker.skyblock.item.tooltip.CompactorDeletorPreview; +import de.hysky.skyblocker.skyblock.quicknav.QuickNav; +import de.hysky.skyblocker.skyblock.quicknav.QuickNavButton; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.gui.ContainerSolver; @@ -41,6 +43,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -89,10 +92,22 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen @Final protected T handler; + @Unique + private List<QuickNavButton> quickNavButtons; + protected HandledScreenMixin(Text title) { super(title); } + @Inject(method = "init", at = @At("RETURN")) + private void skyblocker$initQuickNav(CallbackInfo ci) { + if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().quickNav.enableQuickNav && client != null && client.player != null && !client.player.isCreative()) { + for (QuickNavButton quickNavButton : quickNavButtons = QuickNav.init(getTitle().getString().trim())) { + addSelectableChild(quickNavButton); + } + } + } + @Inject(at = @At("HEAD"), method = "keyPressed") public void skyblocker$keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) { if (this.client != null && this.focusedSlot != null && keyCode != 256) { @@ -109,8 +124,33 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen @Inject(at = @At("HEAD"), method = "mouseClicked") public void skyblocker$mouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) { - if (SkyblockerConfigManager.get().farming.garden.visitorHelper && (Utils.getLocationRaw().equals("garden") && !getTitle().getString().contains("Logbook") || getTitle().getString().startsWith("Bazaar"))) + if (SkyblockerConfigManager.get().farming.garden.visitorHelper && (Utils.getLocationRaw().equals("garden") && !getTitle().getString().contains("Logbook") || getTitle().getString().startsWith("Bazaar"))) { VisitorHelper.onMouseClicked(mouseX, mouseY, button, this.textRenderer); + } + } + + /** + * Draws the unselected tabs in front of the background blur, but behind the main inventory, similar to creative inventory tabs + */ + @Inject(method = "renderBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/gui/DrawContext;FII)V")) + private void skyblocker$drawUnselectedQuickNavButtons(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { + if (quickNavButtons != null) for (QuickNavButton quickNavButton : quickNavButtons) { + if (!quickNavButton.toggled()) { + quickNavButton.render(context, mouseX, mouseY, delta); + } + } + } + + /** + * Draws the selected tab in front of the background blur and the main inventory, similar to creative inventory tabs + */ + @Inject(method = "renderBackground", at = @At("RETURN")) + private void skyblocker$drawSelectedQuickNavButtons(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { + if (quickNavButtons != null) for (QuickNavButton quickNavButton : quickNavButtons) { + if (quickNavButton.toggled()) { + quickNavButton.render(context, mouseX, mouseY, delta); + } + } } @SuppressWarnings("DataFlowIssue") @@ -165,7 +205,7 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen /** * The naming of this method in yarn is half true, its mostly to handle slot/item interactions (which are mouse or keyboard clicks) * For example, using the drop key bind while hovering over an item will invoke this method to drop the players item - * + * * @implNote This runs before {@link ScreenHandler#onSlotClick(int, int, SlotActionType, net.minecraft.entity.player.PlayerEntity)} */ @Inject(method = "onMouseClick(Lnet/minecraft/screen/slot/Slot;IILnet/minecraft/screen/slot/SlotActionType;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;clickSlot(IIILnet/minecraft/screen/slot/SlotActionType;Lnet/minecraft/entity/player/PlayerEntity;)V"), cancellable = true) diff --git a/src/main/java/de/hysky/skyblocker/mixins/accessors/HandledScreenAccessor.java b/src/main/java/de/hysky/skyblocker/mixins/accessors/HandledScreenAccessor.java index 447031d4..9a2a8311 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/accessors/HandledScreenAccessor.java +++ b/src/main/java/de/hysky/skyblocker/mixins/accessors/HandledScreenAccessor.java @@ -2,6 +2,7 @@ package de.hysky.skyblocker.mixins.accessors; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; @@ -23,4 +24,7 @@ public interface HandledScreenAccessor { @Mutable @Accessor("handler") void setHandler(ScreenHandler handler); + + @Accessor("focusedSlot") + Slot getFocusedSlot(); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java index a6adf66b..5fa517cc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNav.java @@ -1,20 +1,16 @@ package de.hysky.skyblocker.skyblock.quicknav; import com.mojang.brigadier.exceptions.CommandSyntaxException; - import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.QuickNavigationConfig; -import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.datafixer.ItemStackComponentizationFixer; -import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import net.fabricmc.fabric.api.client.screen.v1.Screens; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.text.Text; import net.minecraft.util.Formatting; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,16 +21,6 @@ import java.util.regex.PatternSyntaxException; public class QuickNav { private static final Logger LOGGER = LoggerFactory.getLogger(QuickNav.class); - public static void init() { - ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> { - if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().quickNav.enableQuickNav && screen instanceof HandledScreen<?> && client.player != null && !client.player.isCreative()) { - String screenTitle = screen.getTitle().getString().trim(); - List<QuickNavButton> buttons = QuickNav.init(screenTitle); - for (QuickNavButton button : buttons) Screens.getButtons(screen).add(button); - } - }); - } - public static List<QuickNavButton> init(String screenTitle) { List<QuickNavButton> buttons = new ArrayList<>(); QuickNavigationConfig data = SkyblockerConfigManager.get().quickNav; @@ -51,6 +37,8 @@ public class QuickNav { if (data.button10.render) buttons.add(parseButton(data.button10, screenTitle, 9)); if (data.button11.render) buttons.add(parseButton(data.button11, screenTitle, 10)); if (data.button12.render) buttons.add(parseButton(data.button12, screenTitle, 11)); + if (data.button13.render) buttons.add(parseButton(data.button13, screenTitle, 12)); + if (data.button14.render) buttons.add(parseButton(data.button14, screenTitle, 13)); } catch (CommandSyntaxException e) { LOGGER.error("[Skyblocker] Failed to initialize Quick Nav Button", e); } @@ -58,22 +46,19 @@ public class QuickNav { } private static QuickNavButton parseButton(QuickNavigationConfig.QuickNavItem buttonInfo, String screenTitle, int id) throws CommandSyntaxException { - QuickNavigationConfig.ItemData itemData = buttonInfo.item; - ItemStack stack = ItemStackComponentizationFixer.fromComponentsString(itemData.id, Math.clamp(itemData.count, 1, 99), itemData.components); - boolean uiTitleMatches = false; + QuickNavigationConfig.ItemData itemData = buttonInfo.itemData; + ItemStack stack = itemData != null && itemData.item != null && itemData.components != null ? ItemStackComponentizationFixer.fromComponentsString(itemData.item.toString(), Math.clamp(itemData.count, 1, 99), itemData.components) : new ItemStack(Items.BARRIER); + boolean uiTitleMatches = false; try { uiTitleMatches = screenTitle.matches(buttonInfo.uiTitle); } catch (PatternSyntaxException e) { - LOGGER.error("[Skyblocker] Failed to parse Quick Nav Button", e); + LOGGER.error("[Skyblocker] Failed to parse Quick Nav Button with regex: {}", buttonInfo.uiTitle, e); ClientPlayerEntity player = MinecraftClient.getInstance().player; if (player != null) { - player.sendMessage(Text.of(Formatting.RED + "[Skyblocker] Invalid regex in quicknav button " + (id + 1) + "!"), false); + player.sendMessage(Constants.PREFIX.get().append(Text.literal("Invalid regex in Quick Nav Button " + (id + 1) + "!").formatted(Formatting.RED)), false); } } - return new QuickNavButton(id, - uiTitleMatches, - buttonInfo.clickEvent, - stack); + return new QuickNavButton(id, uiTitleMatches, buttonInfo.clickEvent, stack); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java index 7db78590..f9ca0940 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java @@ -1,7 +1,6 @@ package de.hysky.skyblocker.skyblock.quicknav; import com.mojang.blaze3d.systems.RenderSystem; - import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; import net.fabricmc.api.EnvType; @@ -16,7 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -@Environment(value=EnvType.CLIENT) +@Environment(value = EnvType.CLIENT) public class QuickNavButton extends ClickableWidget { private final int index; private boolean toggled; @@ -25,18 +24,24 @@ public class QuickNavButton extends ClickableWidget { /** * Checks if the current tab is a top tab based on its index. - * @return true if the index is less than 6, false otherwise. + * + * @return true if the index is less than 7, false otherwise. */ private boolean isTopTab() { - return index < 6; + return index < 7; + } + + public boolean toggled() { + return toggled; } /** * Constructs a new QuickNavButton with the given parameters. - * @param index the index of the button. + * + * @param index the index of the button. * @param toggled the toggled state of the button. * @param command the command to execute when the button is clicked. - * @param icon the icon to display on the button. + * @param icon the icon to display on the button. */ public QuickNavButton(int index, boolean toggled, String command, ItemStack icon) { super(0, 0, 26, 32, Text.empty()); @@ -49,18 +54,18 @@ public class QuickNavButton extends ClickableWidget { private void updateCoordinates() { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen instanceof HandledScreen<?> handledScreen) { - int x = ((HandledScreenAccessor)handledScreen).getX(); - int y = ((HandledScreenAccessor)handledScreen).getY(); - int h = ((HandledScreenAccessor)handledScreen).getBackgroundHeight(); - if (h > 166) --h; // why is this even a thing - this.setX(x + this.index % 6 * 26 + 4); - this.setY(this.index < 6 ? y - 26 : y + h - 4); + int x = ((HandledScreenAccessor) handledScreen).getX(); + int y = ((HandledScreenAccessor) handledScreen).getY(); + int h = ((HandledScreenAccessor) handledScreen).getBackgroundHeight(); + this.setX(x + this.index % 7 * 25); + this.setY(this.index < 7 ? y - 28 : y + h - 4); } } /** * Handles click events. If the button is not currently toggled, * it sets the toggled state to true and sends a message with the command after cooldown. + * * @param mouseX the x-coordinate of the mouse click * @param mouseY the y-coordinate of the mouse click */ @@ -78,9 +83,10 @@ public class QuickNavButton extends ClickableWidget { * The method first updates the coordinates of the button, * then calculates appropriate values for rendering based on its current state, * and finally draws both the background and icon of the button on screen. + * * @param context the context in which to render the button - * @param mouseX the x-coordinate of the mouse cursor - * @param mouseY the y-coordinate of the mouse cursor + * @param mouseX the x-coordinate of the mouse cursor + * @param mouseY the y-coordinate of the mouse cursor */ @Override public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { @@ -88,31 +94,16 @@ public class QuickNavButton extends ClickableWidget { RenderSystem.disableDepthTest(); // Construct the texture identifier based on the index and toggled state - String tabType = isTopTab() ? "top" : "bottom"; - Identifier BUTTON_TEXTURES = new Identifier("container/creative_inventory/tab_" + tabType + - (toggled ? "_selected_" : "_unselected_") + 2); + Identifier tabTexture = new Identifier("container/creative_inventory/tab_" + (isTopTab() ? "top" : "bottom") + "_" + (toggled ? "selected" : "unselected") + "_" + (index % 7 + 1)); // Render the button texture - int y = this.getY(); - if (this.toggled) { - if (this.index < 6) y -= 2; - } else { - y += (this.index >= 6) ? 4 : -2; - } - int height = this.height - ((this.toggled ) ? 0 : 4); - - context.drawGuiTexture(BUTTON_TEXTURES, this.getX(), y, this.width, height); - + context.drawGuiTexture(tabTexture, this.getX(), this.getY(), this.width, this.height); // Render the button icon - int yOffset = !this.toggled && this.index < 6 ? 1 : 0; - context.drawItem(this.icon, this.getX() + 5, this.getY() + 6 + yOffset); - + int yOffset = this.index < 7 ? 1 : -1; + context.drawItem(this.icon, this.getX() + 5, this.getY() + 8 + yOffset); RenderSystem.enableDepthTest(); } - @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) { - // TODO Auto-generated method stub - - } + @Override + protected void appendClickableNarrations(NarrationMessageBuilder builder) {} } diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index 086686a7..1aa77080 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -1,6 +1,5 @@ package de.hysky.skyblocker.utils; -import com.google.gson.Gson; import com.google.gson.JsonParser; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; @@ -9,6 +8,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.hysky.skyblocker.SkyblockerMod; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.component.ComponentChanges; @@ -49,7 +49,6 @@ public class ItemUtils { private static final DateTimeFormatter OLD_OBTAINED_DATE_FORMAT = DateTimeFormatter.ofPattern("M/d/yy h:m a").withZone(ZoneId.of("UTC")).localizedBy(Locale.ENGLISH); public static final Pattern NOT_DURABILITY = Pattern.compile("[^0-9 /]"); public static final Predicate<String> FUEL_PREDICATE = line -> line.contains("Fuel: "); - private static final Gson GSON = new Gson(); //GSON Instance with no config private static final Codec<RegistryEntry<Item>> EMPTY_ALLOWING_ITEM_CODEC = Registries.ITEM.getEntryCodec(); public static final Codec<ItemStack> EMPTY_ALLOWING_ITEMSTACK_CODEC = Codec.lazyInitialized(() -> RecordCodecBuilder.create(instance -> instance.group( EMPTY_ALLOWING_ITEM_CODEC.fieldOf("id").forGetter(ItemStack::getRegistryEntry), @@ -59,7 +58,7 @@ public class ItemUtils { public static LiteralArgumentBuilder<FabricClientCommandSource> dumpHeldItemCommand() { return literal("dumpHeldItem").executes(context -> { - context.getSource().sendFeedback(Text.literal("[Skyblocker Debug] Held Item: " + GSON.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, context.getSource().getPlayer().getMainHandStack()).getOrThrow()))); + context.getSource().sendFeedback(Text.literal("[Skyblocker Debug] Held Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, context.getSource().getPlayer().getMainHandStack()).getOrThrow()))); return Command.SINGLE_SUCCESS; }); } |