Skip to content

Commit

Permalink
Add 1.20.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 17, 2024
1 parent 879e7fc commit 3071953
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 3 additions & 45 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
70 changes: 70 additions & 0 deletions build_dep_ver.gradle
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static void tick(float partialTicks, float hitDistance) {
pickedComments.clear();
for (Map<BlockPos, List<CommentEntry>> region : ClientWorldData.INSTANCE.regions.values()) {
for (Map.Entry<BlockPos, List<CommentEntry>> 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<Vec3> clipPos = blockHitArea.clip(pickStart, pickEnd);
boolean isPicked = clipPos.isPresent() && clipPos.get().distanceToSqr(pickStart) < vanillaDistSqr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -222,6 +225,7 @@ public void render(#if MC_VERSION >= "12000" GuiGraphics #else PoseStack #endif
}
}
guiGraphics.pose().popPose();
super.render(guiParam, mouseX, mouseY, partialTick);
}
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,8 +64,8 @@ public void onClose() {
private List<CommentTypeButton> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,4 @@ public net.minecraft.client.gui.components.Button build() {
}
}

#else

public class Button {

}

#endif
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3071953

Please sign in to comment.