diff --git a/build.gradle.kts b/build.gradle.kts index c3a3d92..6124c09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ jfMod { minecraftVersion = "1.21" yarn("build.1") loaderVersion = "0.15.11" - libJfVersion = "3.16.0" + libJfVersion = "3.17.0-SNAPSHOT" fabricApiVersion = "0.100.1+1.21" modrinth { @@ -55,6 +55,7 @@ dependencies { modImplementation("io.gitlab.jfronny.libjf:libjf-data-manipulation-v0") modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v2") modImplementation("io.gitlab.jfronny.libjf:libjf-config-ui-tiny") + modImplementation("io.gitlab.jfronny.libjf:libjf-resource-pack-entry-widgets-v0") val nofabric: Action = Action { exclude("net.fabricmc") // required to work around duplicate fabric loaders diff --git a/settings.gradle.kts b/settings.gradle.kts index 4482c32..2c8c521 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,6 @@ pluginManagement { repositories { - maven("https://maven.fabricmc.net/") // FabricMC - maven("https://maven.frohnmeyer-wds.de/artifacts") // scripts -// maven("https://maven.architectury.dev/") // Architectury -// maven("https://files.minecraftforge.net/maven/") // Forge + maven("https://maven.frohnmeyer-wds.de/mirrors") gradlePluginPortal() } } diff --git a/src/client/java/io/gitlab/jfronny/respackopts/RespackoptsPackWidget.java b/src/client/java/io/gitlab/jfronny/respackopts/RespackoptsPackWidget.java new file mode 100644 index 0000000..ef85d0a --- /dev/null +++ b/src/client/java/io/gitlab/jfronny/respackopts/RespackoptsPackWidget.java @@ -0,0 +1,40 @@ +package io.gitlab.jfronny.respackopts; + +import com.mojang.blaze3d.systems.RenderSystem; +import io.gitlab.jfronny.libjf.config.api.v2.ConfigInstance; +import io.gitlab.jfronny.libjf.config.api.v2.dsl.DSL; +import io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory; +import io.gitlab.jfronny.libjf.entrywidgets.api.v0.ResourcePackEntryWidget; +import io.gitlab.jfronny.respackopts.model.cache.CacheKey; +import io.gitlab.jfronny.respackopts.util.MetaCache; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer; +import net.minecraft.util.Identifier; + +public class RespackoptsPackWidget implements ResourcePackEntryWidget { + @Override + public boolean isVisible(ResourcePackOrganizer.Pack pack, boolean selectable) { + return selectable && MetaCache.getKeyByDisplayName(pack.getDisplayName().getString()) != null; + } + + @Override + public void render(ResourcePackOrganizer.Pack pack, DrawContext context, int x, int y, boolean hovered, float tickDelta) { + RenderSystem.setShaderColor(1, 1, 1, 1f); + RenderSystem.disableDepthTest(); + context.drawTexture(Identifier.of("modmenu", "textures/gui/configure_button.png"), x, y, 0, hovered ? 20 : 0, 20, 20, 32, 64); + RenderSystem.enableDepthTest(); + } + + @Override + public void onClick(ResourcePackOrganizer.Pack pack) { + CacheKey dataLocation = MetaCache.getKeyByDisplayName(pack.getDisplayName().getString()); + if (dataLocation != null) { + MinecraftClient c = MinecraftClient.getInstance(); + String id = MetaCache.getId(dataLocation); + ConfigInstance ci = DSL.create(id).config(builder -> MetaCache.getBranch(dataLocation).buildConfig(builder, id, dataLocation.dataLocation())); + ConfigScreenFactory.Built screen = ConfigScreenFactory.getInstance().create(ci, c.currentScreen); + c.setScreen(screen.get()); + } + } +} diff --git a/src/client/java/io/gitlab/jfronny/respackopts/mixin/ResourcePackEntryMixin.java b/src/client/java/io/gitlab/jfronny/respackopts/mixin/ResourcePackEntryMixin.java deleted file mode 100644 index b126659..0000000 --- a/src/client/java/io/gitlab/jfronny/respackopts/mixin/ResourcePackEntryMixin.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.gitlab.jfronny.respackopts.mixin; - -import com.mojang.blaze3d.systems.RenderSystem; -import io.gitlab.jfronny.libjf.config.api.v2.ConfigInstance; -import io.gitlab.jfronny.libjf.config.api.v2.dsl.DSL; -import io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory; -import io.gitlab.jfronny.respackopts.model.cache.CacheKey; -import io.gitlab.jfronny.respackopts.util.MetaCache; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.pack.PackListWidget; -import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(PackListWidget.ResourcePackEntry.class) -public abstract class ResourcePackEntryMixin { - @Final @Shadow private PackListWidget widget; - @Shadow protected abstract boolean isSelectable(); - @Shadow @Final private ResourcePackOrganizer.Pack pack; - @Unique boolean rpo$selected; - - @Inject(at = @At("TAIL"), method = "render(Lnet/minecraft/client/gui/DrawContext;IIIIIIIZF)V") - private void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta, CallbackInfo info) { - if (this.isSelectable() && MetaCache.getKeyByDisplayName(pack.getDisplayName().getString()) != null) { - int d = mouseX - x; - d = widget.getRowWidth() - d; - int e = mouseY - y; - rpo$selected = d <= 32 && d >= 12 && e <= entryHeight / 2 + 10 && e >= entryHeight / 2 - 10; - rpo$renderButton(context, rpo$selected, Identifier.of("modmenu", "textures/gui/configure_button.png"), x + entryWidth - 30, y + entryHeight / 2 - 10); - } - } - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AlwaysSelectedEntryListWidget$Entry;mouseClicked(DDI)Z"), method = "mouseClicked(DDI)Z", cancellable = true) - public void mouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable info) { - // Inject before super call - if (this.isSelectable()) { - CacheKey dataLocation = MetaCache.getKeyByDisplayName(pack.getDisplayName().getString()); - if (dataLocation != null && rpo$selected) { - info.setReturnValue(true); - MinecraftClient c = MinecraftClient.getInstance(); - String id = MetaCache.getId(dataLocation); - ConfigInstance ci = DSL.create(id).config(builder -> MetaCache.getBranch(dataLocation).buildConfig(builder, id, dataLocation.dataLocation())); - ConfigScreenFactory.Built screen = ConfigScreenFactory.getInstance().create(ci, c.currentScreen); - c.setScreen(screen.get()); - } - } - } - - @Unique - private void rpo$renderButton(DrawContext context, boolean hovered, Identifier texture, int x, int y) { - RenderSystem.setShaderColor(1, 1, 1, 1f); - RenderSystem.disableDepthTest(); - context.drawTexture(texture, x, y, 0, hovered ? 20 : 0, 20, 20, 32, 64); - RenderSystem.enableDepthTest(); - } -} diff --git a/src/client/resources/respackopts.client.mixins.json b/src/client/resources/respackopts.client.mixins.json index 93578fa..fa1ea16 100644 --- a/src/client/resources/respackopts.client.mixins.json +++ b/src/client/resources/respackopts.client.mixins.json @@ -8,7 +8,6 @@ "LanguageManagerMixin", "OptionsScreenMixin", "PackScreenMixin", - "ResourcePackEntryMixin", "TranslationStorageAccessor" ], "injectors": { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4f03608..ea0debc 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,6 +21,7 @@ "respackopts:save_hook": ["io.gitlab.jfronny.respackopts.Respackopts"], "respackopts:client_save_hook": ["io.gitlab.jfronny.respackopts.RespackoptsClient"], "libjf:config": ["io.gitlab.jfronny.respackopts.RespackoptsConfig"], + "libjf:resource_pack_entry_widget": ["io.gitlab.jfronny.respackopts.RespackoptsPackWidget"], "modmenu": ["io.gitlab.jfronny.respackopts.integration.ModMenuIntegration"] }, "mixins": [