Skip to content

Commit

Permalink
libjf 3.17.0 and move from PackMixinHelper to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
adam committed Aug 3, 2024
1 parent 852f35b commit 1f62b91
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 118 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Boolean> 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();
}
Expand Down

0 comments on commit 1f62b91

Please sign in to comment.