From 89b6382eef8f6bf69ae90c135d427e1b3dd9a120 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Wed, 21 Dec 2022 17:02:22 +0530 Subject: [PATCH] Port to Minecraft 1.19.3 - Upgrade to Minecraft 1.19.3 - Upgrade to Gradle 7.6 - Upgrade to Fabric Loom 1.0 - Upgrade to Fabric Loader 0.14.11 - Upgrade to Yarn Mappings 1.19.3+build.3 - Upgrade to Fabric API 0.69.1+1.19.3 - Change build.gradle, settings.gradle to fix warnings. - Change references that were renamed in updated Yarn (shaders, canHit). - Migrate to JOML, which replaced Minecraft's built-in math classes. --- build.gradle | 55 ++++++++++--------- gradle.properties | 10 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 1 - .../torohealth/bars/HealthBarRenderer.java | 12 ++-- .../torohealth/bars/ParticleRenderer.java | 8 +-- .../torohealth/display/BarDisplay.java | 2 +- .../torohealth/display/EntityDisplay.java | 11 ++-- .../torohealth/mixin/WorldRendererMixin.java | 2 +- .../torocraft/torohealth/util/RayTrace.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 11 files changed, 54 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 65cae4f..e503ec3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.12-SNAPSHOT' + id 'fabric-loom' version '1.0-SNAPSHOT' id 'maven-publish' } @@ -10,6 +10,13 @@ archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group +repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. +} dependencies { //to change the versions see the gradle.properties file @@ -23,48 +30,44 @@ dependencies { } processResources { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - - inputs.property "version", project.mod_version + inputs.property "version", project.version filesMatching("fabric.mod.json") { expand "version": project.version } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() } jar { - from "LICENSE" + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } } // configure the maven publication publishing { publications { mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } - gpr(MavenPublication) { - from(components.java) + from components.java } } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } } diff --git a/gradle.properties b/gradle.properties index fe474fb..6276f02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,14 +8,14 @@ org.gradle.jvmargs=-Xmx1G # To remap the mixin locations: # gradlew migrateMappings --mappings "1.16.1+build.9" -minecraft_version=1.19 -yarn_mappings=1.19+build.1 -loader_version=0.14.6 +minecraft_version=1.19.3 +yarn_mappings=1.19.3+build.3 +loader_version=0.14.11 #Fabric api -fabric_version=0.55.2+1.19 +fabric_version=0.69.1+1.19.3 # Mod Properties -mod_version = 1.19-fabric-1 +mod_version = 1.19.3-fabric-1 maven_group = net.torocraft archives_base_name = torohealth diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8a17ae4..594324a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 5b60df3..f91a4fe 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index 10ec0ca..33c05bb 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -14,15 +14,15 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Matrix4f; +import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; import net.torocraft.torohealth.ToroHealth; import net.torocraft.torohealth.config.Config; import net.torocraft.torohealth.config.Config.InWorld; import net.torocraft.torohealth.config.Config.Mode; import net.torocraft.torohealth.util.EntityUtil; import net.torocraft.torohealth.util.EntityUtil.Relation; +import org.joml.Matrix4f; import org.lwjgl.opengl.GL11; public class HealthBarRenderer { @@ -87,7 +87,7 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) { return; } - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(GameRenderer::getPositionColorProgram); RenderSystem.enableDepthTest(); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, @@ -110,8 +110,8 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) { matrix.push(); matrix.translate(x - camX, (y + height) - camY, z - camZ); - matrix.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-camera.getYaw())); - matrix.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(camera.getPitch())); + matrix.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw())); + matrix.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); matrix.scale(-scaleToGui, -scaleToGui, scaleToGui); render(matrix, entity, 0, 0, FULL_SIZE, true); @@ -183,7 +183,7 @@ private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float b = (color & 255) / 255.0F; RenderSystem.setShaderColor(r, g, b, 1); - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderTexture(0, GUI_BARS_TEXTURES); RenderSystem.enableBlend(); diff --git a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java index b0a83cb..6e0c815 100644 --- a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java @@ -6,8 +6,8 @@ import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3f; import net.torocraft.torohealth.ToroHealth; import org.lwjgl.opengl.GL11; @@ -41,11 +41,11 @@ private static void renderParticle(MatrixStack matrix, BarParticle particle, Cam matrix.push(); matrix.translate(x - camX, y - camY, z - camZ); - matrix.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-camera.getYaw())); - matrix.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(camera.getPitch())); + matrix.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-camera.getYaw())); + matrix.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); matrix.scale(-scaleToGui, -scaleToGui, scaleToGui); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(GameRenderer::getPositionColorProgram); RenderSystem.enableDepthTest(); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index 376bc2f..58a4af5 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -29,7 +29,7 @@ public void draw(MatrixStack matrix, LivingEntity entity) { int xOffset = 0; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderTexture(0, ICON_TEXTURES); RenderSystem.enableBlend(); diff --git a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java index 1bb390c..97b1fca 100644 --- a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java @@ -11,8 +11,8 @@ import net.minecraft.entity.passive.ChickenEntity; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Quaternion; -import net.minecraft.util.math.Vec3f; +import net.minecraft.util.math.RotationAxis; +import org.joml.Quaternionf; public class EntityDisplay { @@ -82,10 +82,9 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, matrixStack2.push(); matrixStack2.translate(0.0D, 0.0D, 1000.0D); matrixStack2.scale((float) size, (float) size, (float) size); - Quaternion quaternion = Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0F); - Quaternion quaternion2 = Vec3f.POSITIVE_X.getDegreesQuaternion(g * 20.0F); - quaternion.hamiltonProduct(quaternion2); - matrixStack2.multiply(quaternion); + Quaternionf quaternion = RotationAxis.POSITIVE_Z.rotationDegrees(180.0F); + Quaternionf quaternion2 = RotationAxis.POSITIVE_X.rotationDegrees(g * 20.0F); + matrixStack2.multiply(quaternion.mul(quaternion2)); float h = entity.bodyYaw; float i = entity.getYaw(); float j = entity.getPitch(); diff --git a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java index 8e1fc4f..ef44f10 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java @@ -9,9 +9,9 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.math.Matrix4f; import net.torocraft.torohealth.bars.HealthBarRenderer; import net.torocraft.torohealth.bars.ParticleRenderer; +import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/net/torocraft/torohealth/util/RayTrace.java b/src/main/java/net/torocraft/torohealth/util/RayTrace.java index 6610328..b513f75 100644 --- a/src/main/java/net/torocraft/torohealth/util/RayTrace.java +++ b/src/main/java/net/torocraft/torohealth/util/RayTrace.java @@ -24,7 +24,7 @@ import net.minecraft.world.RaycastContext.FluidHandling; public class RayTrace implements BlockView { - private static Predicate isVisible = entity -> !entity.isSpectator() && entity.collides(); + private static Predicate isVisible = entity -> !entity.isSpectator() && entity.canHit(); private static MinecraftClient minecraft = MinecraftClient.getInstance(); @Override diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 16604a7..74108f3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ "modmenu": "*" }, "depends": { - "fabricloader": ">=0.14.6", + "fabricloader": ">=0.14.11", "fabric": "*", "minecraft": "1.19.x", "java": ">=17"