From 1f62b91fc2b67fa18a6a0932990c3becdc7dd0d5 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 3 Aug 2024 20:57:56 +0300 Subject: [PATCH] libjf 3.17.0 and move from PackMixinHelper to widget --- common/build.gradle | 2 +- .../DynamicPackResourcePackEntryWidget.java | 35 ++++++++++- .../DynamicPackResourcePackEntryWidget2.java | 55 ----------------- .../dynamicpack/client/PackMixinHelper.java | 60 ------------------- 4 files changed, 34 insertions(+), 118 deletions(-) delete mode 100644 common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget2.java diff --git a/common/build.gradle b/common/build.gradle index 6337b65..3e670d0 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -27,7 +27,7 @@ loom { dependencies { modImplementation("dev.isxander:yet-another-config-lib:3.5.0+1.21-fabric") - modImplementation("io.gitlab.jfronny.libjf:libjf-resource-pack-entry-widgets-v0:3.17.0-SNAPSHOT") + modImplementation("io.gitlab.jfronny.libjf:libjf-resource-pack-entry-widgets-v0:3.17.0") minecraft "com.mojang:minecraft:${minecraft_version}" mappings loom.officialMojangMappings() diff --git a/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget.java b/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget.java index 045a7ce..9d9c791 100644 --- a/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget.java +++ b/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget.java @@ -3,8 +3,10 @@ import com.adamcalculator.dynamicpack.DynamicPackMod; import com.adamcalculator.dynamicpack.pack.DynamicResourcePack; import io.gitlab.jfronny.libjf.entrywidgets.api.v0.ResourcePackEntryWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.packs.PackSelectionModel; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; public class DynamicPackResourcePackEntryWidget implements ResourcePackEntryWidget { @@ -18,7 +20,7 @@ public void render(PackSelectionModel.Entry entry1, GuiGraphics context, int x, DynamicResourcePack pack = getDynamicPackFromArgs(entry1); if (pack != null) { - PackMixinHelper.drawTexture(context, pack, x, y, hovered); + drawTexture(context, pack, x, y, hovered); } } @@ -46,11 +48,40 @@ public int getXMargin(PackSelectionModel.Entry pack) { public void onClick(PackSelectionModel.Entry entry) { DynamicResourcePack pack = getDynamicPackFromArgs(entry); if (pack != null) { - PackMixinHelper.openPackScreen(pack); + openPackScreen(pack); } } private @Nullable DynamicResourcePack getDynamicPackFromArgs(PackSelectionModel.Entry entry) { return DynamicPackMod.getDynamicPackByMinecraftName(entry.getId()); } + + private static final ResourceLocation BUTTON_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button.png"); + private static final ResourceLocation BUTTON_WARNING_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button_warning.png"); + private static final ResourceLocation BUTTON_SYNCING_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button_syncing.png"); + + public static void drawTexture(GuiGraphics context, DynamicResourcePack pack, int x, int y, boolean hovered) { + Exception latestException = pack.getLatestException(); + if (pack.isSyncing()) { + Compat.drawTexture(context, BUTTON_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); + + + double alpha = System.currentTimeMillis() / 200d; + int xshift = (int) (Math.sin(alpha) * 6.9d); + int yshift = (int) (Math.cos(alpha) * 6.9d); + + Compat.drawTexture(context, BUTTON_SYNCING_TEXTURE, x + xshift+6, y + yshift+6, 0.0F, (hovered ? 16f : 0f), 4, 4, 16, 32); + + } else if (latestException != null) { + Compat.drawTexture(context, BUTTON_WARNING_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); + + } else { + Compat.drawTexture(context, BUTTON_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); + } + } + + public static void openPackScreen(DynamicResourcePack pack) { + Minecraft.getInstance().setScreen(new DynamicPackScreen(Minecraft.getInstance().screen, pack)); + } + } diff --git a/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget2.java b/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget2.java deleted file mode 100644 index 077a7f5..0000000 --- a/common/src/main/java/com/adamcalculator/dynamicpack/client/DynamicPackResourcePackEntryWidget2.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.adamcalculator.dynamicpack.client; - -import com.adamcalculator.dynamicpack.DynamicPackMod; -import com.adamcalculator.dynamicpack.pack.DynamicResourcePack; -import io.gitlab.jfronny.libjf.entrywidgets.api.v0.ResourcePackEntryWidget; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screens.packs.PackSelectionModel; -import org.jetbrains.annotations.Nullable; - -public class DynamicPackResourcePackEntryWidget2 implements ResourcePackEntryWidget { - @Override - public boolean isVisible(PackSelectionModel.Entry pack, boolean selectable) { - return getDynamicPackFromArgs(pack) != null; - } - - @Override - public void render(PackSelectionModel.Entry entry1, GuiGraphics context, int x, int y, boolean hovered, float tickDelta) { - DynamicResourcePack pack = getDynamicPackFromArgs(entry1); - if (pack != null) { - PackMixinHelper.drawTexture(context, pack, x, y, !hovered); - } - } - - @Override - public int getWidth(PackSelectionModel.Entry pack) { - return 16; - } - - @Override - public int getHeight(PackSelectionModel.Entry pack, int rowHeight) { - return 16; - } - - @Override - public int getY(PackSelectionModel.Entry pack, int rowHeight) { - return 14; - } - - @Override - public int getXMargin(PackSelectionModel.Entry pack) { - return 2; - } - - @Override - public void onClick(PackSelectionModel.Entry entry) { - DynamicResourcePack pack = getDynamicPackFromArgs(entry); - if (pack != null) { - PackMixinHelper.openPackScreen(pack); - } - } - - private @Nullable DynamicResourcePack getDynamicPackFromArgs(PackSelectionModel.Entry entry) { - return DynamicPackMod.getDynamicPackByMinecraftName(entry.getId()); - } -} diff --git a/common/src/main/java/com/adamcalculator/dynamicpack/client/PackMixinHelper.java b/common/src/main/java/com/adamcalculator/dynamicpack/client/PackMixinHelper.java index 964dba5..6497e53 100644 --- a/common/src/main/java/com/adamcalculator/dynamicpack/client/PackMixinHelper.java +++ b/common/src/main/java/com/adamcalculator/dynamicpack/client/PackMixinHelper.java @@ -1,68 +1,8 @@ package com.adamcalculator.dynamicpack.client; import com.adamcalculator.dynamicpack.DynamicPackMod; -import com.adamcalculator.dynamicpack.pack.DynamicResourcePack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screens.packs.TransferableSelectionList; -import net.minecraft.resources.ResourceLocation; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class PackMixinHelper { - private static final ResourceLocation BUTTON_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button.png"); - private static final ResourceLocation BUTTON_WARNING_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button_warning.png"); - private static final ResourceLocation BUTTON_SYNCING_TEXTURE = ResourceLocation.tryBuild("dynamicpack", "select_button_syncing.png"); - - public static void drawTexture(GuiGraphics context, DynamicResourcePack pack, int x, int y, boolean hovered) { - Exception latestException = pack.getLatestException(); - if (pack.isSyncing()) { - Compat.drawTexture(context, BUTTON_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); - - - double alpha = System.currentTimeMillis() / 200d; - int xshift = (int) (Math.sin(alpha) * 6.9d); - int yshift = (int) (Math.cos(alpha) * 6.9d); - - Compat.drawTexture(context, BUTTON_SYNCING_TEXTURE, x + xshift+6, y + yshift+6, 0.0F, (hovered ? 16f : 0f), 4, 4, 16, 32); - - } else if (latestException != null) { - Compat.drawTexture(context, BUTTON_WARNING_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); - - } else { - Compat.drawTexture(context, BUTTON_TEXTURE, x, y, 0.0F, (hovered ? 16f : 0f), 16, 16, 16, 32); - } - } - - public static void renderResourcePackEntry(Object resourcePackEntryMixin, GuiGraphics context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta, CallbackInfo ci) { - TransferableSelectionList.PackEntry entry = (TransferableSelectionList.PackEntry) resourcePackEntryMixin; - DynamicResourcePack pack = DynamicPackMod.getInstance().getDynamicPackByMinecraftName(entry.getPackId()); - if (pack != null) { - int i = mouseX - x; - int j = mouseY - y; - drawTexture(context, pack, x, y, hovered); - } - } - - public static void mouseClicked(Object resourcePackEntryMixin, TransferableSelectionList widget, double mouseX, double mouseY, int button, CallbackInfoReturnable cir) { - TransferableSelectionList.PackEntry entry = (TransferableSelectionList.PackEntry) resourcePackEntryMixin; - DynamicResourcePack pack = DynamicPackMod.getInstance().getDynamicPackByMinecraftName(entry.getPackId()); - if (pack != null) { - double d = mouseX - (double)widget.getRowLeft(); - double e = mouseY - (double)widget.getRowTop(widget.children().indexOf(entry)); - - if (d >= 174) { - if (e >= 16) { - openPackScreen(pack); - } - } - } - } - - public static void openPackScreen(DynamicResourcePack pack) { - Minecraft.getInstance().setScreen(new DynamicPackScreen(Minecraft.getInstance().screen, pack)); - } - public static void minecraftInitReturned() { DynamicPackMod.getInstance().minecraftInitialized(); }