From 37b2f7060dd8fa5be7b89e04967216455fdccc0a Mon Sep 17 00:00:00 2001 From: sisby-folk Date: Sat, 30 Nov 2024 17:38:06 +1100 Subject: [PATCH] shard collection button --- build.gradle | 4 ++++ gradle.properties | 2 +- libs.versions.toml | 4 ++++ .../scatteredshards/ScatteredShards.java | 3 +++ .../ScatteredShardsConfig.java | 10 +++++++++ .../mixin/client/GameMenuScreenMixin.java | 22 +++++++++++++++++++ .../assets/scattered_shards/lang/en_us.json | 1 + src/main/resources/fabric.mod.json | 3 +++ .../resources/scattered_shards.mixins.json | 12 ++++++++++ 9 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/modfest/scatteredshards/ScatteredShardsConfig.java create mode 100644 src/main/java/net/modfest/scatteredshards/mixin/client/GameMenuScreenMixin.java create mode 100644 src/main/resources/scattered_shards.mixins.json diff --git a/build.gradle b/build.gradle index c9443e1..b7e3723 100644 --- a/build.gradle +++ b/build.gradle @@ -12,9 +12,13 @@ archivesBaseName = project.slug repositories { maven { url "https://server.bbkr.space/artifactory/libs-release" } maven { url "https://oss.sonatype.org/content/repositories/snapshots" } + maven { url "https://repo.sleeping.town/" } } dependencies { + implementation libs.kaleidoConfig + include libs.kaleidoConfig + minecraft libs.mc mappings variantOf(libs.yarn) { classifier "v2" } diff --git a/gradle.properties b/gradle.properties index b1c4706..9b2c11b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ authors=Falkreon, acikek contributors=Trudle, Tomate0613, afamiliarquiet, FoundationGames, TheEpicBlock, hama license=MIT # Mod Version -baseVersion=1.7.1 +baseVersion=1.7.2 # Branch Metadata branch=1.21 tagBranch=1.21 diff --git a/libs.versions.toml b/libs.versions.toml index 1afb88f..039b45c 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,6 +2,8 @@ loom = "1.7.+" minotaur = "2.+" +kaleidoConfig = "0.3.1+1.3.1" + mc = "1.21.1" fl = "0.16.7" yarn = "1.21.1+build.3" @@ -15,6 +17,8 @@ loom = { id = "fabric-loom", version.ref = "loom" } minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" } [libraries] +kaleidoConfig = { group = "folk.sisby", name = "kaleido-config", version.ref = "kaleidoConfig" } + mc = { group = "mojang", name = "minecraft", version.ref = "mc" } fl = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fl" } yarn = { group = "net.fabricmc", name = "yarn", version.ref = "yarn" } diff --git a/src/main/java/net/modfest/scatteredshards/ScatteredShards.java b/src/main/java/net/modfest/scatteredshards/ScatteredShards.java index 786da73..42ea0c9 100644 --- a/src/main/java/net/modfest/scatteredshards/ScatteredShards.java +++ b/src/main/java/net/modfest/scatteredshards/ScatteredShards.java @@ -2,6 +2,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Identifier; import net.modfest.scatteredshards.api.ScatteredShardsAPI; import net.modfest.scatteredshards.api.shard.ShardType; @@ -17,6 +18,8 @@ public class ScatteredShards implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger(ID); + public static final ScatteredShardsConfig CONFIG = ScatteredShardsConfig.createToml(FabricLoader.getInstance().getConfigDir(), "", ID, ScatteredShardsConfig.class); + public static Identifier id(String path) { return Identifier.of(ID, path); } diff --git a/src/main/java/net/modfest/scatteredshards/ScatteredShardsConfig.java b/src/main/java/net/modfest/scatteredshards/ScatteredShardsConfig.java new file mode 100644 index 0000000..7a83086 --- /dev/null +++ b/src/main/java/net/modfest/scatteredshards/ScatteredShardsConfig.java @@ -0,0 +1,10 @@ +package net.modfest.scatteredshards; + +import folk.sisby.kaleido.api.ReflectiveConfig; +import folk.sisby.kaleido.lib.quiltconfig.api.annotations.Comment; +import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue; + +public class ScatteredShardsConfig extends ReflectiveConfig { + @Comment("Whether to replace advancements button with a shard collection button") + public final TrackedValue replace_advancements = value(true); +} diff --git a/src/main/java/net/modfest/scatteredshards/mixin/client/GameMenuScreenMixin.java b/src/main/java/net/modfest/scatteredshards/mixin/client/GameMenuScreenMixin.java new file mode 100644 index 0000000..2f1526a --- /dev/null +++ b/src/main/java/net/modfest/scatteredshards/mixin/client/GameMenuScreenMixin.java @@ -0,0 +1,22 @@ +package net.modfest.scatteredshards.mixin.client; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.client.gui.screen.GameMenuScreen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.GridWidget; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.text.Text; +import net.modfest.scatteredshards.ScatteredShards; +import net.modfest.scatteredshards.client.ScatteredShardsClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(GameMenuScreen.class) +public class GameMenuScreenMixin { + @WrapOperation(method = "initWidgets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 0)) + private Widget replaceAdvancements(GridWidget.Adder instance, Widget widget, Operation original) { + if (!ScatteredShards.CONFIG.replace_advancements.value()) return original.call(instance, widget); + return instance.add(ButtonWidget.builder(Text.translatable("menu.scattered_shards.collection"), b -> ScatteredShardsClient.openShardTablet()).width(98).build()); + } +} diff --git a/src/main/resources/assets/scattered_shards/lang/en_us.json b/src/main/resources/assets/scattered_shards/lang/en_us.json index 9492566..bb250bf 100644 --- a/src/main/resources/assets/scattered_shards/lang/en_us.json +++ b/src/main/resources/assets/scattered_shards/lang/en_us.json @@ -32,6 +32,7 @@ "gui.scattered_shards.tablet.tooltip.global_collection": "%s of players have this shard", "gui.scattered_shards.tablet.label.progress.started": "%s Started", "gui.scattered_shards.tablet.label.progress.total": "%s Total", + "menu.scattered_shards.collection": "Shard Collection", "toast.scattered_shards.shard_mod.title": "Shard Modification", "toast.scattered_shards.shard_mod.success": "Successfully modified '%s'", "toast.scattered_shards.shard_mod.fail": "Failed to modify '%s'", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e1b0ca2..f02da06 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,6 +17,9 @@ }, "license": "${license}", "icon": "assets/${modId}/icon.png", + "mixins": [ + "${modId}.mixins.json" + ], "depends": { "minecraft": ">=${mc}", "fabricloader": ">=${fl}", diff --git a/src/main/resources/scattered_shards.mixins.json b/src/main/resources/scattered_shards.mixins.json new file mode 100644 index 0000000..2ca0a4e --- /dev/null +++ b/src/main/resources/scattered_shards.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.modfest.scatteredshards.mixin", + "compatibilityLevel": "JAVA_21", + "client": [ + "client.GameMenuScreenMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}