From 30719537997b5be825a6a6053f8fcfbf30022aab Mon Sep 17 00:00:00 2001 From: zbx1425 Date: Wed, 17 Jan 2024 22:33:10 +0800 Subject: [PATCH] Add 1.20.4 support --- .github/workflows/build.yml | 2 +- build.gradle | 48 +------------ build_dep_ver.gradle | 70 +++++++++++++++++++ .../data/client/ClientRayPicking.java | 4 +- .../worldcomment/gui/CommentListScreen.java | 21 +++--- .../worldcomment/gui/CommentToolScreen.java | 24 +++---- .../worldcomment/gui/WidgetColorButton.java | 10 +++ .../worldcomment/gui/WidgetCommentEntry.java | 1 + .../worldcomment/util/compat/Button.java | 6 -- .../worldcomment/util/compat/Checkbox.java | 44 ++++++++++++ 10 files changed, 156 insertions(+), 74 deletions(-) create mode 100644 build_dep_ver.gradle create mode 100644 common/src/main/java/cn/zbx1425/worldcomment/util/compat/Checkbox.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56a01a6..bb545d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - minecraft: [ 1.19.2, 1.20.1 ] + minecraft: [ 1.19.2, 1.20.1, 1.20.4 ] runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/build.gradle b/build.gradle index 5dbd9f9..06356dc 100644 --- a/build.gradle +++ b/build.gradle @@ -5,56 +5,14 @@ import java.nio.file.Files plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false id "de.undercouch.download" version "4.1.2" id "com.github.johnrengelman.shadow" version "7.1.0" id "io.github.pacifistmc.forgix" version "1.2.6" id "base" } -String default_minecraft_version = "1.20.1" -Properties localProperties = new Properties() -String minecraft_version -if (project.rootProject.file('build.properties').exists()) { - localProperties.load(project.rootProject.file('build.properties').newDataInputStream()) -} -if (localProperties.containsKey("MC_VERSION")) { - String notDotted = localProperties.get("MC_VERSION") - String dotted = notDotted.substring(0, 1) + "." + - Integer.toString(Integer.parseInt(notDotted.substring(1, 3))) + "." + - Integer.toString(Integer.parseInt(notDotted.substring(3, 5))) - minecraft_version = dotted -} else { - minecraft_version = rootProject.properties.containsKey("buildVersion") ? rootProject.properties.get("buildVersion") : default_minecraft_version -} -int minecraft_main_version = minecraft_version.split("\\.")[1] as int -String minecraft_version_int = minecraft_version.split("\\.")[0] + - minecraft_version.split("\\.")[1].padLeft(2, '0') + - (minecraft_version.split("\\.").length > 2 ? minecraft_version.split("\\.")[2].padLeft(2, '0') : "00") -boolean parchment_not_avail = false -String parchment_version = parchment_not_avail ? "N/A" : new XmlSlurper().parse("https://ldtteam.jfrog.io/artifactory/parchmentmc-internal/org/parchmentmc/data/parchment-${minecraft_version}/maven-metadata.xml").versioning.release - - -rootProject.ext.fabric_loader_version = new JsonSlurper().parse(("https://meta.fabricmc.net/v2/versions/loader/" + minecraft_version).toURL())[0]["loader"]["version"] -rootProject.ext.forge_version = minecraft_version + "-" + new JsonSlurper().parse(("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").toURL())["promos"][minecraft_version + "-recommended"] -rootProject.ext.fabric_api_version = getModrinthVersion("fabric", minecraft_version, "fabric-api") -rootProject.ext.mod_menu_version = getModrinthVersion("fabric", minecraft_version, "modmenu") -rootProject.ext.architectury_version = getModrinthVersion("forge", minecraft_version, "architectury-api").split("\\+")[0] - -rootProject.ext.architectury_id = minecraft_main_version == 16 ? "me.shedaniel" : "dev.architectury" - -rootProject.ext.supports_minecraft_version = [ - "1.16.5": "1.16.x", - "1.17.1": "1.17.x", "1.18.2": "1.18.x", - "1.19.2": "1.19.2", "1.19.4": "1.19.4", - "1.20.1": "1.20.x" -][minecraft_version] -rootProject.ext.supports_minecraft_version_range = [ - "1.16.5": "[1.16, 1.17)", - "1.17.1": "[1.17, 1.18)", "1.18.2": "[1.18, 1.19)", - "1.19.2": "1.19.2", "1.19.4": "1.19.4", - "1.20.1": "[1.20, 1.21)" -][minecraft_version] +apply from: "build_dep_ver.gradle" architectury { minecraft = minecraft_version @@ -74,7 +32,7 @@ subprojects { dependencies { annotationProcessor 'systems.manifold:manifold-preprocessor:+' minecraft "com.mojang:minecraft:${minecraft_version}" - mappings parchment_not_avail ? loom.officialMojangMappings() : loom.layered() { + mappings parchment_version == "" ? loom.officialMojangMappings() : loom.layered() { officialMojangMappings() parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") } diff --git a/build_dep_ver.gradle b/build_dep_ver.gradle new file mode 100644 index 0000000..0ad9a8c --- /dev/null +++ b/build_dep_ver.gradle @@ -0,0 +1,70 @@ +String default_minecraft_version = "1.19.2" +Properties localProperties = new Properties() +String minecraft_version +if (project.rootProject.file('build.properties').exists()) { + localProperties.load(project.rootProject.file('build.properties').newDataInputStream()) +} +if (localProperties.containsKey("MC_VERSION")) { + String notDotted = localProperties.get("MC_VERSION") + String dotted = notDotted.substring(0, 1) + "." + + Integer.toString(Integer.parseInt(notDotted.substring(1, 3))) + "." + + Integer.toString(Integer.parseInt(notDotted.substring(3, 5))) + minecraft_version = dotted +} else { + minecraft_version = rootProject.properties.containsKey("buildVersion") ? rootProject.properties.get("buildVersion") : default_minecraft_version +} +rootProject.ext.minecraft_version = minecraft_version +rootProject.ext.minecraft_main_version = minecraft_version.split("\\.")[1] as int +rootProject.ext.minecraft_version_int = minecraft_version.split("\\.")[0] + + minecraft_version.split("\\.")[1].padLeft(2, '0') + + (minecraft_version.split("\\.").length > 2 ? minecraft_version.split("\\.")[2].padLeft(2, '0') : "00") +rootProject.ext.is_1_19_3 = minecraft_version == "1.19.3" || minecraft_version == "1.19.4" +rootProject.ext.is_1_20 = minecraft_version == "1.20" || minecraft_version == "1.20.1" + +rootProject.ext.supports_minecraft_version = [ + "1.16.5": "1.16.x", + "1.17.1": "1.17.x", "1.18.2": "1.18.x", + "1.19.2": "1.19.2", "1.19.3": "1.19.3", "1.19.4": "1.19.4", + "1.20.1": "1.20.x", "1.20.4": "1.20.x" +][minecraft_version] +rootProject.ext.supports_minecraft_version_range = [ + "1.16.5": "[1.16, 1.17)", + "1.17.1": "[1.17, 1.18)", "1.18.2": "[1.18, 1.19)", + "1.19.2": "1.19.2", "1.19.3": "1.19.3", "1.19.4": "1.19.4", + "1.20.1": "[1.20, 1.21)", "1.20.4": "1.20.x" +][minecraft_version] + +rootProject.ext.parchment_version = [ + "1.16.5": "2022.03.06", + "1.17.1": "2021.12.12", "1.18.2": "2022.11.06", + "1.19.2": "2022.11.27", "1.19.3": "2023.06.25", "1.19.4": "2023.06.26", + "1.20.1": "2023.09.03", "1.20.4": "" +][minecraft_version] + +rootProject.ext.fabric_loader_version = "0.15.3" +rootProject.ext.fabric_api_version = [ + "1.16.5": "0.42.0", + "1.17.1": "0.46.1+1.17", "1.18.2": "0.77.0+1.18.2", + "1.19.2": "0.77.0+1.19.2", "1.19.3": "0.76.1+1.19.3", "1.19.4": "0.87.2+1.19.4", + "1.20.1": "0.91.0+1.20.1", "1.20.4": "0.93.1+1.20.4" +][minecraft_version] +rootProject.ext.mod_menu_version = [ + "1.16.5": "1.16.23", + "1.17.1": "2.0.17", "1.18.2": "3.2.5", + "1.19.2": "4.1.2", "1.19.3": "5.1.0", "1.19.4": "6.3.1", + "1.20.1": "7.2.2", "1.20.4": "9.0.0" +][minecraft_version] + +rootProject.ext.forge_version = minecraft_version + "-" + [ + "1.16.5": "36.2.34", + "1.17.1": "37.1.1", "1.18.2": "40.2.0", + "1.19.2": "43.3.0", "1.19.3": "44.1.0", "1.19.4": "45.2.0", + "1.20.1": "47.2.0", "1.20.4": "49.0.19" +][minecraft_version] +rootProject.ext.architectury_version = [ + "1.16.5": "1.32.68", + "1.17.1": "2.10.12", "1.18.2": "4.11.93", + "1.19.2": "6.5.85", "1.19.3": "7.1.86", "1.19.4": "8.2.89", + "1.20.1": "9.1.12", "1.20.4": "11.0.11" +][minecraft_version] +rootProject.ext.architectury_id = minecraft_main_version == 16 ? "me.shedaniel" : "dev.architectury" diff --git a/common/src/main/java/cn/zbx1425/worldcomment/data/client/ClientRayPicking.java b/common/src/main/java/cn/zbx1425/worldcomment/data/client/ClientRayPicking.java index c884844..fb051fd 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/data/client/ClientRayPicking.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/data/client/ClientRayPicking.java @@ -43,7 +43,9 @@ public static void tick(float partialTicks, float hitDistance) { pickedComments.clear(); for (Map> region : ClientWorldData.INSTANCE.regions.values()) { for (Map.Entry> blockData : region.entrySet()) { - AABB blockHitArea = new AABB(blockData.getKey(), blockData.getKey().offset(1, 3, 1)); + BlockPos bp = blockData.getKey(); + AABB blockHitArea = new AABB(bp.getX(), bp.getY(), bp.getZ(), + bp.getX() + 1, bp.getY() + 3, bp.getZ() + 1); if (!((LevelRendererAccessor)minecraft.levelRenderer).getCullingFrustum().isVisible(blockHitArea)) continue; Optional clipPos = blockHitArea.clip(pickStart, pickEnd); boolean isPicked = clipPos.isPresent() && clipPos.get().distanceToSqr(pickStart) < vanillaDistSqr; diff --git a/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentListScreen.java b/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentListScreen.java index dc119f2..a4d3e38 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentListScreen.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentListScreen.java @@ -113,7 +113,10 @@ void useSubScreen(int subScreen) { public void render(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif guiParam, int mouseX, int mouseY, float partialTick) { GuiGraphics guiGraphics = #if MC_VERSION >= "12000" guiParam #else GuiGraphics.withPose(guiParam) #endif ; Minecraft minecraft = Minecraft.getInstance(); - renderBackground(guiParam); + #if MC_VERSION < "12002" renderBackground(guiParam); #endif + guiGraphics.pose().pushPose(); + guiGraphics.pose().translate(0, 0, 1); + guiGraphics.drawString(minecraft.font, Component.translatable("gui.worldcomment.list.title"), 40, 15, 0xFFFFE6C0, true); @@ -222,6 +225,7 @@ public void render(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif } } + guiGraphics.pose().popPose(); super.render(guiParam, mouseX, mouseY, partialTick); } @@ -282,9 +286,10 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } @Override - public void renderBackground(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif guiParam) { + public void renderBackground(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif guiParam + #if MC_VERSION >= "12002", int mouseX, int mouseY, float partialTick #endif) { GuiGraphics guiGraphics = #if MC_VERSION >= "12000" guiParam #else GuiGraphics.withPose(guiParam) #endif ; - super.renderBackground(guiParam); + super.renderBackground(guiParam #if MC_VERSION >= "12002", mouseX, mouseY, partialTick #endif); graphicsBlit9(guiGraphics, 30, 10, width - 40, height - 20, 196, 40, 20, 20, 256, 256, 4, 4, 4, 4 @@ -294,18 +299,18 @@ public void renderBackground(#if MC_VERSION >= "12000" GuiGraphics #else PoseSta private double accumulatedScroll = 0; @Override - public boolean mouseScrolled(double mouseX, double mouseY, double delta) { - if (this.accumulatedScroll != 0.0 && Math.signum(delta) != Math.signum(this.accumulatedScroll)) { + public boolean mouseScrolled(double mouseX, double mouseY #if MC_VERSION >= "12002", double deltaX #endif, double deltaY) { + if (this.accumulatedScroll != 0.0 && Math.signum(deltaY) != Math.signum(this.accumulatedScroll)) { this.accumulatedScroll = 0.0; } - this.accumulatedScroll += delta; + this.accumulatedScroll += deltaY; int scrollAmount = (int)this.accumulatedScroll; - if (scrollAmount == 0) return super.mouseScrolled(mouseX, mouseY, delta); + if (scrollAmount == 0) return super.mouseScrolled(mouseX, mouseY #if MC_VERSION >= "12002", deltaX #endif, deltaY); this.accumulatedScroll -= scrollAmount; if (commentList.size() <= 1) { commentListOffset = 0; - return super.mouseScrolled(mouseX, mouseY, delta); + return super.mouseScrolled(mouseX, mouseY #if MC_VERSION >= "12002", deltaX #endif, deltaY); } int dir = -(int)Math.signum(scrollAmount); commentListOffset = Mth.clamp(commentListOffset + dir, 0, Math.max(commentList.size() - 1, 0)); diff --git a/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentToolScreen.java b/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentToolScreen.java index 2d5ad51..5070c4f 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentToolScreen.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/gui/CommentToolScreen.java @@ -11,6 +11,7 @@ #if MC_VERSION >= "12000" import net.minecraft.ChatFormatting; #endif import net.minecraft.client.Minecraft; #if MC_VERSION >= "12000" import net.minecraft.client.gui.GuiGraphics; #else import cn.zbx1425.worldcomment.util.compat.GuiGraphics; import com.mojang.blaze3d.vertex.PoseStack; #endif +#if MC_VERSION < "12003" import cn.zbx1425.worldcomment.util.compat.Checkbox; #endif import net.minecraft.client.gui.components.*; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; @@ -63,8 +64,8 @@ public void onClose() { private List radioButtons = new ArrayList<>(); private WidgetUnmanagedImage widgetImage; private MultiLineEditBox textBoxMessage; - private Checkbox checkBoxNoImage; - private Checkbox checkBoxAnonymous; + private net.minecraft.client.gui.components.Checkbox checkBoxNoImage; + private net.minecraft.client.gui.components.Checkbox checkBoxAnonymous; private WidgetColorButton btnSaveScreenshot; private Button btnSendFeedback; private int selectedCommentType = 0; @@ -147,18 +148,14 @@ protected void init() { widgetImage.setBounds(0, baseY, SIDEBAR_OFFSET - SQ_SIZE); addRenderableWidget(widgetImage); baseY += widgetImage.getHeight() + SQ_SIZE / 2; - checkBoxNoImage = new Checkbox( - 0, baseY, SIDEBAR_OFFSET - SQ_SIZE, SQ_SIZE, - Component.translatable("gui.worldcomment.exclude_screenshot"), - false, true - ); + checkBoxNoImage = Checkbox + .builder(Component.translatable("gui.worldcomment.exclude_screenshot"), minecraft.font) + .pos(0, baseY).selected(false).build(); addRenderableWidget(checkBoxNoImage); baseY += SQ_SIZE; - checkBoxAnonymous = new Checkbox( - 0, baseY, SIDEBAR_OFFSET - SQ_SIZE, SQ_SIZE, - Component.translatable("gui.worldcomment.anonymous"), - false, true - ); + checkBoxAnonymous = Checkbox + .builder(Component.translatable("gui.worldcomment.anonymous"), minecraft.font) + .pos(0, baseY).selected(false).build(); addRenderableWidget(checkBoxAnonymous); int maxX = 0, maxY = 0; @@ -238,9 +235,10 @@ private void sendReport() { @Override public void render(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif guiParam, int mouseX, int mouseY, float partialTick) { GuiGraphics guiGraphics = #if MC_VERSION >= "12000" guiParam #else GuiGraphics.withPose(guiParam) #endif ; - renderBackground(guiParam); + #if MC_VERSION < "12002" renderBackground(guiParam); #endif guiGraphics.pose().pushPose(); setupAnimationTransform(guiGraphics); + guiGraphics.pose().translate(0, 0, 1); guiGraphics.fill( containerOffsetX - CONTAINER_PADDING_X, diff --git a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetColorButton.java b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetColorButton.java index 094b316..86a5391 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetColorButton.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetColorButton.java @@ -3,8 +3,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; #if MC_VERSION >= "12000" import net.minecraft.client.gui.GuiGraphics; #else import cn.zbx1425.worldcomment.util.compat.GuiGraphics; import com.mojang.blaze3d.vertex.PoseStack; #endif +#if MC_VERSION >= "12002" import net.minecraft.client.gui.components.WidgetSprites; #endif import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; #if MC_VERSION >= "12000" import java.util.function.Supplier; #endif @@ -18,6 +20,10 @@ public WidgetColorButton(int i, int j, int k, int l, Component component, int co this.color = color; } +#if MC_VERSION >= "12002" + private static final WidgetSprites SPRITES = new WidgetSprites(new ResourceLocation("widget/button"), new ResourceLocation("widget/button_disabled"), new ResourceLocation("widget/button_highlighted")); +#endif + @Override #if MC_VERSION >= "12000" protected void renderWidget(GuiGraphics guiParam, int mouseX, int mouseY, float partialTick) { @@ -36,7 +42,11 @@ public void render(PoseStack guiParam, int mouseX, int mouseY, float partialTick } RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); +#if MC_VERSION >= "12002" + guiGraphics.blitSprite(SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight()); +#else guiGraphics.blitNineSliced(WIDGETS_LOCATION, this #if MC_VERSION >= "11903" .getX() #else .x #endif, this #if MC_VERSION >= "11903" .getY() #else .y #endif, this.getWidth(), this.getHeight(), 20, 4, 200, 20, 0, this.getTextureY()); +#endif guiGraphics.setColor(1.0f, 1.0f, 1.0f, 1.0f); int i = this.active ? 0xFFFFFF : 0xA0A0A0; this.renderString(guiGraphics, minecraft.font, i | Mth.ceil(this.alpha * 255.0f) << 24); diff --git a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java index cc78a4d..eec59a7 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java @@ -69,6 +69,7 @@ protected void renderWidget(GuiGraphics guiParam, int mouseX, int mouseY, float public void render(PoseStack guiParam, int mouseX, int mouseY, float partialTick) { final GuiGraphics guiGraphics = GuiGraphics.withPose(guiParam); #endif + graphicsBlit9( guiGraphics, getX(), getY(), getWidth(), getHeight(), 0, 0, 128, 48, 256, 256, diff --git a/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Button.java b/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Button.java index 78d89c7..1dc0cfe 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Button.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Button.java @@ -51,10 +51,4 @@ public net.minecraft.client.gui.components.Button build() { } } -#else - -public class Button { - -} - #endif diff --git a/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Checkbox.java b/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Checkbox.java new file mode 100644 index 0000000..abd6791 --- /dev/null +++ b/common/src/main/java/cn/zbx1425/worldcomment/util/compat/Checkbox.java @@ -0,0 +1,44 @@ +package cn.zbx1425.worldcomment.util.compat; + +#if MC_VERSION < "12003" + +import net.minecraft.client.gui.Font; +import net.minecraft.network.chat.Component; + +public class Checkbox { + + public static Checkbox.Builder builder(Component var0, Font var1) { + return new Checkbox.Builder(var0, var1); + } + + public static class Builder { + private final Component message; + private int x; + private int y; + private boolean selected = false; + + public Builder(Component var1, Font ignored) { + this.message = var1; + } + + public Checkbox.Builder pos(int var1, int var2) { + this.x = var1; + this.y = var2; + return this; + } + + public Checkbox.Builder selected(boolean var1) { + this.selected = var1; + return this; + } + + public net.minecraft.client.gui.components.Checkbox build() { + net.minecraft.client.gui.components.Checkbox var1 = + new net.minecraft.client.gui.components.Checkbox(this.x, this.y, 800, 20, + this.message, this.selected, true); + return var1; + } + } +} + +#endif