From 659917bed95b7a82803390cfb62edbe35f84b85a Mon Sep 17 00:00:00 2001 From: Dianliang233 Date: Thu, 12 Dec 2024 12:27:18 +0800 Subject: [PATCH] Port to 1.21.4 --- build.gradle.kts | 2 +- .../heywiki/gui/screen/WikiSearchScreen.java | 2 +- .../heywiki/gui/widget/DropdownWidget.java | 164 ------------------ .../gui/widget/SuggestionEntryWidget.java | 2 +- .../heywiki/resource/WikiFamilyManager.java | 3 +- gradle.properties | 18 +- 6 files changed, 14 insertions(+), 177 deletions(-) delete mode 100644 common/src/main/java/wiki/minecraft/heywiki/gui/widget/DropdownWidget.java diff --git a/build.gradle.kts b/build.gradle.kts index e848ab25..c504e969 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("architectury-plugin") version "3.4-SNAPSHOT" - id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false + id("dev.architectury.loom") version "1.9-SNAPSHOT" apply false java } diff --git a/common/src/main/java/wiki/minecraft/heywiki/gui/screen/WikiSearchScreen.java b/common/src/main/java/wiki/minecraft/heywiki/gui/screen/WikiSearchScreen.java index 4f0d139d..f458c70b 100644 --- a/common/src/main/java/wiki/minecraft/heywiki/gui/screen/WikiSearchScreen.java +++ b/common/src/main/java/wiki/minecraft/heywiki/gui/screen/WikiSearchScreen.java @@ -227,7 +227,7 @@ private void fetchImage(SearchProvider.Suggestion suggestion) { var textureId = id(hash); assert this.client != null; - if (this.client.getTextureManager().getOrDefault(textureId, null) != null) return; + if (this.client.getTextureManager().getTexture(textureId) != null) return; this.executor.execute(() -> this.textures.add(textureId)); byte[] imageArray = HttpUtil.loadAndCacheFile(imageUrl).join(); diff --git a/common/src/main/java/wiki/minecraft/heywiki/gui/widget/DropdownWidget.java b/common/src/main/java/wiki/minecraft/heywiki/gui/widget/DropdownWidget.java deleted file mode 100644 index 513fcae6..00000000 --- a/common/src/main/java/wiki/minecraft/heywiki/gui/widget/DropdownWidget.java +++ /dev/null @@ -1,164 +0,0 @@ -package wiki.minecraft.heywiki.gui.widget; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.widget.ElementListWidget; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; - -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; - -public class DropdownWidget extends ElementListWidget> { - private static final MinecraftClient client = MinecraftClient.getInstance(); - public static final int ENTRY_HEIGHT = 15; - protected final List entries; - protected final Consumer selectCallback; - private final Runnable onToggle; - protected T prevSelected; - protected T selected; - protected boolean open; - private final Function entryToText; - - public DropdownWidget(MinecraftClient minecraftClient, int x, int y, int width, int maxHeight, List entries, - Function entryToText, Consumer selectCallback, T selected, - Runnable onToggle) { - super(minecraftClient, width, Math.min((entries.size() + 1) * ENTRY_HEIGHT + 8, maxHeight), y, ENTRY_HEIGHT); - this.onToggle = onToggle; - setX(x); - this.entries = entries; - this.selectCallback = selectCallback; - this.selected = selected; - this.entryToText = entryToText; - setRenderHeader(true, ENTRY_HEIGHT + 4); - for (T entry : entries) { - addEntry(new Entry<>(this, entry, entryToText)); - } - } - - public boolean isOpen() { - return this.open; - } - - @Override - public int getRowLeft() { - return getX(); - } - - @Override - public int getRowWidth() { - return getWidth(); - } - - @Override - public int getHeight() { - return open ? super.getHeight() : ENTRY_HEIGHT + 8; - } - - @Override - protected boolean clickedHeader(int x, int y) { - open = !open; - this.onToggle.run(); - return true; - } - - @Override - protected void renderHeader(DrawContext context, int x, int y) { - context.drawTextWithShadow(client.textRenderer, this.entryToText.apply(selected), x + 4, y + 2, 0xFFFFFFFF); - } - - @Override - public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { - context.getMatrices().push(); - context.getMatrices().translate(0, 0, 100); - - int y = getY() - (int) getScrollAmount(); - int height = getMaxPosition(); - - context.fill(getX(), y, getX() + width, y + headerHeight, 0xFF000000); - context.drawHorizontalLine(getX(), getX() + width, y, 0xFFFFFFFF); - context.drawHorizontalLine(getX(), getX() + width, y + headerHeight, 0xFFFFFFFF); - context.drawVerticalLine(getX(), y, y + headerHeight, 0xFFFFFFFF); - context.drawVerticalLine(getX() + width, y, y + headerHeight, 0xFFFFFFFF); - - if (open) { - context.fill(getX(), y + headerHeight + 1, getX() + width, y + height, 0xFF000000); - context.drawHorizontalLine(getX(), getX() + width, y + height, 0xFFFFFFFF); - context.drawVerticalLine(getX(), y + headerHeight, y + height, 0xFFFFFFFF); - context.drawVerticalLine(getX() + width, y + headerHeight, y + height, 0xFFFFFFFF); - - super.renderWidget(context, mouseX, mouseY, delta); - } else { - renderHeader(context, getRowLeft(), y + 4); - } - - context.getMatrices().pop(); - } - - @Override - protected void drawMenuListBackground(DrawContext context) {} - - @Override - protected void drawHeaderAndFooterSeparators(DrawContext context) {} - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - return open && super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); - } - - protected void select(T entry) { - selected = entry; - open = false; - this.onToggle.run(); - setScrollAmount(0); - if (selected != prevSelected) { - selectCallback.accept(entry); - prevSelected = selected; - } - } - - static class Entry extends ElementListWidget.Entry> { - private final DropdownWidget dropdownWidget; - private final T entry; - private final Function entryToText; - - public Entry(DropdownWidget dropdownWidget, T entry, Function entryToText) { - this.dropdownWidget = dropdownWidget; - this.entry = entry; - this.entryToText = entryToText; - } - - @Override - public List selectableChildren() { - return List.of(); - } - - @Override - public List children() { - return List.of(); - } - - @Override - public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, - int mouseY, boolean hovered, float tickDelta) { - context.drawTextWithShadow(client.textRenderer, - this.entryToText.apply(entry).fillStyle(Style.EMPTY.withUnderline(hovered)), - x + 14, y + 2, 0xFFFFFFFF); - if (dropdownWidget.selected == this.entry) { - context.drawTextWithShadow(client.textRenderer, "✔", x + 4, y + 2, 0xFFFFFFFF); - } - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (button == 0 && dropdownWidget.open) { - dropdownWidget.select(entry); - return true; - } - return super.mouseClicked(mouseX, mouseY, button); - } - } -} \ No newline at end of file diff --git a/common/src/main/java/wiki/minecraft/heywiki/gui/widget/SuggestionEntryWidget.java b/common/src/main/java/wiki/minecraft/heywiki/gui/widget/SuggestionEntryWidget.java index 75d5e57c..cb245230 100644 --- a/common/src/main/java/wiki/minecraft/heywiki/gui/widget/SuggestionEntryWidget.java +++ b/common/src/main/java/wiki/minecraft/heywiki/gui/widget/SuggestionEntryWidget.java @@ -101,7 +101,7 @@ public void render(DrawContext DrawContext, int index, int y, int x, int rowWidt String hash = Hex.encodeHexString(md.digest(imageUrl.getBytes(StandardCharsets.UTF_8))); var identifier = id(hash); - AbstractTexture texture = client.getTextureManager().getOrDefault(identifier, null); + AbstractTexture texture = client.getTextureManager().getTexture(identifier); return texture != null ? identifier : null; }).orElse(null); } diff --git a/common/src/main/java/wiki/minecraft/heywiki/resource/WikiFamilyManager.java b/common/src/main/java/wiki/minecraft/heywiki/resource/WikiFamilyManager.java index 149f6614..004f63e4 100644 --- a/common/src/main/java/wiki/minecraft/heywiki/resource/WikiFamilyManager.java +++ b/common/src/main/java/wiki/minecraft/heywiki/resource/WikiFamilyManager.java @@ -4,6 +4,7 @@ import com.google.common.collect.HashBiMap; import com.mojang.logging.LogUtils; import net.minecraft.resource.JsonDataLoader; +import net.minecraft.resource.ResourceFinder; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; @@ -27,7 +28,7 @@ public class WikiFamilyManager extends JsonDataLoader { private Map activeWikis = new HashMap<>(); public WikiFamilyManager() { - super(WikiFamily.CODEC, PATH); + super(WikiFamily.CODEC, ResourceFinder.json(PATH)); } /** diff --git a/gradle.properties b/gradle.properties index 1c04e455..692727fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,21 +5,21 @@ archives_base_name=heywiki maven_group=wiki.minecraft.heywiki enabled_platforms=fabric,neoforge enabled_platforms_snapshot=fabric -mod_version=1.7.2+1.21.3 +mod_version=1.7.2+1.21.4 # Loader versions -minecraft_version=1.21.3 -minecraft_version_range=1.21.2,1.21.3 -yarn_mappings=1.21.3+build.2 +minecraft_version=1.21.4 +minecraft_version_range=1.21.4 +yarn_mappings=1.21.4+build.2 fabric_loader_version=0.16.9 -fabric_api_version=0.109.0+1.21.3 -neoforge_version=21.3.40-beta +fabric_api_version=0.111.0+1.21.4 +neoforge_version=21.4.18-beta # Dependency versions -architectury_version=14.0.4 -cloth_config_version=16.0.141 +architectury_version=15.0.1 +cloth_config_version=17.0.142 rei_version=17.0.790 emi_version=1.1.18+1.21.1 jei_minecraft_version=1.21.1 jei_version=19.21.0.247 -modmenu_version=12.0.0-beta.1 +modmenu_version=13.0.0-beta.1 mcbrowser_version=1.1.5 mcef_version=2.1.6-1.21.1 \ No newline at end of file