chore: move pack entry widget logic to LibJF module
This commit is contained in:
parent
65096a6ea4
commit
ba861e2232
@ -30,7 +30,7 @@ jfMod {
|
|||||||
minecraftVersion = "1.21"
|
minecraftVersion = "1.21"
|
||||||
yarn("build.1")
|
yarn("build.1")
|
||||||
loaderVersion = "0.15.11"
|
loaderVersion = "0.15.11"
|
||||||
libJfVersion = "3.16.0"
|
libJfVersion = "3.17.0-SNAPSHOT"
|
||||||
fabricApiVersion = "0.100.1+1.21"
|
fabricApiVersion = "0.100.1+1.21"
|
||||||
|
|
||||||
modrinth {
|
modrinth {
|
||||||
@ -55,6 +55,7 @@ dependencies {
|
|||||||
modImplementation("io.gitlab.jfronny.libjf:libjf-data-manipulation-v0")
|
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-core-v2")
|
||||||
modImplementation("io.gitlab.jfronny.libjf:libjf-config-ui-tiny")
|
modImplementation("io.gitlab.jfronny.libjf:libjf-config-ui-tiny")
|
||||||
|
modImplementation("io.gitlab.jfronny.libjf:libjf-resource-pack-entry-widgets-v0")
|
||||||
|
|
||||||
val nofabric: Action<ExternalModuleDependency> = Action {
|
val nofabric: Action<ExternalModuleDependency> = Action {
|
||||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://maven.fabricmc.net/") // FabricMC
|
maven("https://maven.frohnmeyer-wds.de/mirrors")
|
||||||
maven("https://maven.frohnmeyer-wds.de/artifacts") // scripts
|
|
||||||
// maven("https://maven.architectury.dev/") // Architectury
|
|
||||||
// maven("https://files.minecraftforge.net/maven/") // Forge
|
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<Boolean> 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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,6 @@
|
|||||||
"LanguageManagerMixin",
|
"LanguageManagerMixin",
|
||||||
"OptionsScreenMixin",
|
"OptionsScreenMixin",
|
||||||
"PackScreenMixin",
|
"PackScreenMixin",
|
||||||
"ResourcePackEntryMixin",
|
|
||||||
"TranslationStorageAccessor"
|
"TranslationStorageAccessor"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"respackopts:save_hook": ["io.gitlab.jfronny.respackopts.Respackopts"],
|
"respackopts:save_hook": ["io.gitlab.jfronny.respackopts.Respackopts"],
|
||||||
"respackopts:client_save_hook": ["io.gitlab.jfronny.respackopts.RespackoptsClient"],
|
"respackopts:client_save_hook": ["io.gitlab.jfronny.respackopts.RespackoptsClient"],
|
||||||
"libjf:config": ["io.gitlab.jfronny.respackopts.RespackoptsConfig"],
|
"libjf:config": ["io.gitlab.jfronny.respackopts.RespackoptsConfig"],
|
||||||
|
"libjf:resource_pack_entry_widget": ["io.gitlab.jfronny.respackopts.RespackoptsPackWidget"],
|
||||||
"modmenu": ["io.gitlab.jfronny.respackopts.integration.ModMenuIntegration"]
|
"modmenu": ["io.gitlab.jfronny.respackopts.integration.ModMenuIntegration"]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
Loading…
Reference in New Issue
Block a user