From 89b6382eef8f6bf69ae90c135d427e1b3dd9a120 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Wed, 21 Dec 2022 17:02:22 +0530 Subject: [PATCH 01/11] 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" From 0b1efc167b32f62a3624e13510609d64e820ddb2 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Mon, 3 Apr 2023 20:09:42 +0530 Subject: [PATCH 02/11] Update to Minecraft 1.19.4 Includes updated Gradle, Loom, Yarn, Fabric Loader and Fabric API. --- build.gradle | 2 +- gradle.properties | 10 +++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../net/torocraft/torohealth/display/BarDisplay.java | 2 +- .../java/net/torocraft/torohealth/util/RayTrace.java | 6 ++++-- src/main/resources/fabric.mod.json | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index e503ec3..8208aeb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' + id 'fabric-loom' version '1.1-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 6276f02..874b367 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.3 -yarn_mappings=1.19.3+build.3 -loader_version=0.14.11 +minecraft_version=1.19.4 +yarn_mappings=1.19.4+build.1 +loader_version=0.14.19 #Fabric api -fabric_version=0.69.1+1.19.3 +fabric_version=0.76.0+1.19.4 # Mod Properties -mod_version = 1.19.3-fabric-1 +mod_version = 1.19.4-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 594324a..8510318 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.6-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.0.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index 58a4af5..b0fa9bf 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -40,7 +40,7 @@ public void draw(MatrixStack matrix, LivingEntity entity) { String healthText = healthCur + "/" + healthMax; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - DrawableHelper.drawStringWithShadow(matrix, mc.textRenderer, name, xOffset, (int) 2, 16777215); + DrawableHelper.drawTextWithShadow(matrix, mc.textRenderer, name, xOffset, 2, 16777215); mc.textRenderer.drawWithShadow(matrix, name, xOffset, 2, 16777215); xOffset += mc.textRenderer.getWidth(name) + 5; diff --git a/src/main/java/net/torocraft/torohealth/util/RayTrace.java b/src/main/java/net/torocraft/torohealth/util/RayTrace.java index b513f75..9eda5d9 100644 --- a/src/main/java/net/torocraft/torohealth/util/RayTrace.java +++ b/src/main/java/net/torocraft/torohealth/util/RayTrace.java @@ -103,8 +103,10 @@ public BlockHitResult raycast(RaycastContext context) { VoxelShape blockShape = c.getBlockShape(block, this, pos); return this.raycastBlock(c.getStart(), c.getEnd(), pos, blockShape, block); }, (c) -> { - Vec3d v = c.getStart().subtract(c.getEnd()); - return BlockHitResult.createMissed(c.getEnd(), Direction.getFacing(v.x, v.y, v.z), new BlockPos(c.getEnd())); + Vec3d end = c.getEnd(); + Vec3d v = c.getStart().subtract(end); + BlockPos endBlockPos = new BlockPos((int) end.x, (int) end.y, (int) end.z); + return BlockHitResult.createMissed(end, Direction.getFacing(v.x, v.y, v.z), endBlockPos); }); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 74108f3..43a791d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ "modmenu": "*" }, "depends": { - "fabricloader": ">=0.14.11", + "fabricloader": ">=0.14.18", "fabric": "*", "minecraft": "1.19.x", "java": ">=17" From 469dd22da76d6589fe22fdc6746074254a8c3273 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Tue, 4 Apr 2023 01:15:20 +0530 Subject: [PATCH 03/11] Fix hand rendering issue with in-world health bars --- .../java/net/torocraft/torohealth/bars/HealthBarRenderer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index 33c05bb..1d19463 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -144,6 +144,7 @@ public static void render(MatrixStack matrix, LivingEntity entity, double x, dou drawBar(m4f, x, y, width, 1, DARK_GRAY, zOffset++, inWorld); drawBar(m4f, x, y, width, percent2, color2, zOffset++, inWorld); drawBar(m4f, x, y, width, percent, color, zOffset, inWorld); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); if (!inWorld) { if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.CUMULATIVE)) { From 11c8317d984364ab440ca4975d7f17acfcb6278c Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Sun, 25 Jun 2023 17:57:56 +0530 Subject: [PATCH 04/11] Update to Minecraft 1.20.1 (part 1) - Switch to DrawContext where needed. - Update Gradle, Loom, FLoader/FAPI, Yarn. --- build.gradle | 2 +- gradle.properties | 10 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../torohealth/display/BarDisplay.java | 33 ++++++++----------- .../net/torocraft/torohealth/display/Hud.java | 21 ++++++------ .../torohealth/mixin/InGameHudMixin.java | 6 ++-- .../torohealth/mixin/PlayerEntityMixin.java | 2 +- src/main/resources/fabric.mod.json | 4 +-- 8 files changed, 38 insertions(+), 42 deletions(-) diff --git a/build.gradle b/build.gradle index 8208aeb..da188b8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.2-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 874b367..449ed75 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.4 -yarn_mappings=1.19.4+build.1 -loader_version=0.14.19 +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.8 +loader_version=0.14.21 #Fabric api -fabric_version=0.76.0+1.19.4 +fabric_version=0.84.0+1.20.1 # Mod Properties -mod_version = 1.19.4-fabric-1 +mod_version = 1.20.1-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 8510318..1e836ab 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-8.0.1-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index b0fa9bf..0c712aa 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -2,9 +2,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -14,18 +13,16 @@ public class BarDisplay { private static final Identifier ICON_TEXTURES = new Identifier("textures/gui/icons.png"); private final MinecraftClient mc; - private final DrawableHelper gui; - public BarDisplay(MinecraftClient mc, DrawableHelper gui) { + public BarDisplay(MinecraftClient mc) { this.mc = mc; - this.gui = gui; } private String getEntityName(LivingEntity entity) { return entity.getDisplayName().getString(); } - public void draw(MatrixStack matrix, LivingEntity entity) { + public void draw(DrawContext drawContext, LivingEntity entity) { int xOffset = 0; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -33,40 +30,38 @@ public void draw(MatrixStack matrix, LivingEntity entity) { RenderSystem.setShaderTexture(0, ICON_TEXTURES); RenderSystem.enableBlend(); - HealthBarRenderer.render(matrix, entity, 63, 14, 130, false); + HealthBarRenderer.render(drawContext, entity, 63, 14, 130, false); String name = getEntityName(entity); int healthMax = MathHelper.ceil(entity.getMaxHealth()); int healthCur = Math.min(MathHelper.ceil(entity.getHealth()), healthMax); String healthText = healthCur + "/" + healthMax; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - DrawableHelper.drawTextWithShadow(matrix, mc.textRenderer, name, xOffset, 2, 16777215); + drawContext.drawTextWithShadow(mc.textRenderer, name, xOffset, 2, 16777215); - mc.textRenderer.drawWithShadow(matrix, name, xOffset, 2, 16777215); + drawContext.drawTextWithShadow(mc.textRenderer, name, xOffset, 2, 16777215); xOffset += mc.textRenderer.getWidth(name) + 5; - renderHeartIcon(matrix, xOffset, (int) 1); + renderHeartIcon(drawContext, xOffset, (int) 1); xOffset += 10; - mc.textRenderer.drawWithShadow(matrix, healthText, xOffset, 2, 0xe0e0e0); + drawContext.drawTextWithShadow(mc.textRenderer, healthText, xOffset, 2, 0xe0e0e0); xOffset += mc.textRenderer.getWidth(healthText) + 5; int armor = entity.getArmor(); if (armor > 0) { - renderArmorIcon(matrix, xOffset, (int) 1); + renderArmorIcon(drawContext, xOffset, (int) 1); xOffset += 10; - mc.textRenderer.drawWithShadow(matrix, entity.getArmor() + "", xOffset, 2, 0xe0e0e0); + drawContext.drawTextWithShadow(mc.textRenderer, entity.getArmor() + "", xOffset, 2, 0xe0e0e0); } } - private void renderArmorIcon(MatrixStack matrix, int x, int y) { - RenderSystem.setShaderTexture(0, ICON_TEXTURES); - gui.drawTexture(matrix, x, y, 34, 9, 9, 9); + private void renderArmorIcon(DrawContext drawContext, int x, int y) { + drawContext.drawTexture(ICON_TEXTURES, x, y, 34, 9, 9, 9); } - private void renderHeartIcon(MatrixStack matrix, int x, int y) { - RenderSystem.setShaderTexture(0, ICON_TEXTURES); - gui.drawTexture(matrix, x, y, 16 + 36, 0, 9, 9); + private void renderHeartIcon(DrawContext drawContext, int x, int y) { + drawContext.drawTexture(ICON_TEXTURES, x, y, 16 + 36, 0, 9, 9); } } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index 39480da..dee3222 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; @@ -23,10 +24,10 @@ public class Hud extends Screen { public Hud() { super(Text.literal("ToroHealth HUD")); this.client = MinecraftClient.getInstance(); - barDisplay = new BarDisplay(MinecraftClient.getInstance(), this); + barDisplay = new BarDisplay(MinecraftClient.getInstance()); } - public void draw(MatrixStack matrix, Config config) { + public void draw(DrawContext drawContext, Config config) { if (this.client.options.debugEnabled) { return; } @@ -36,7 +37,7 @@ public void draw(MatrixStack matrix, Config config) { } float x = determineX(); float y = determineY(); - draw(matrix, x, y, config.hud.scale); + draw(drawContext, x, y, config.hud.scale); } private float determineX() { @@ -98,20 +99,21 @@ public LivingEntity getEntity() { return entity; } - private void draw(MatrixStack matrix, float x, float y, float scale) { + private void draw(DrawContext drawContext, float x, float y, float scale) { if (entity == null) { return; } - + if (config.hud.onlyWhenHurt && entity.getHealth() >= entity.getMaxHealth()) { return; } + MatrixStack matrix = drawContext.getMatrices(); matrix.push(); matrix.scale(scale, scale, scale); matrix.translate(x - 10, y - 10, 0); if (config.hud.showSkin) { - this.drawSkin(matrix); + this.drawSkin(drawContext); } matrix.translate(10, 10, 0); if (config.hud.showEntity) { @@ -119,15 +121,14 @@ private void draw(MatrixStack matrix, float x, float y, float scale) { } matrix.translate(44, 0, 0); if (config.hud.showBar) { - barDisplay.draw(matrix, entity); + barDisplay.draw(drawContext, entity); } matrix.pop(); } - private void drawSkin(MatrixStack matrix) { - RenderSystem.setShaderTexture(0, BACKGROUND_TEXTURE); + private void drawSkin(DrawContext drawContext) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int w = 160, h = 60; - drawTexture(matrix, 0, 0, 0.0f, 0.0f, w, h, w, h); + drawContext.drawTexture(BACKGROUND_TEXTURE, 0, 0, 0.0f, 0.0f, w, h, w, h); } } diff --git a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java index 742bbb4..1a43eb7 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java @@ -1,7 +1,7 @@ package net.torocraft.torohealth.mixin; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.util.math.MatrixStack; import net.torocraft.torohealth.ToroHealth; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,8 +12,8 @@ public class InGameHudMixin { @Inject(method = "render", at = @At("RETURN")) - private void render(MatrixStack matrixStack, float partial, CallbackInfo info) { - ToroHealth.HUD.draw(matrixStack, ToroHealth.CONFIG); + private void render(DrawContext drawContext, float partial, CallbackInfo info) { + ToroHealth.HUD.draw(drawContext, ToroHealth.CONFIG); } } diff --git a/src/main/java/net/torocraft/torohealth/mixin/PlayerEntityMixin.java b/src/main/java/net/torocraft/torohealth/mixin/PlayerEntityMixin.java index 0e9042c..b2cfca2 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/PlayerEntityMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/PlayerEntityMixin.java @@ -21,7 +21,7 @@ protected PlayerEntityMixin(EntityType type, World world @Inject(method = "tick()V", at = @At("HEAD")) private void tick(CallbackInfo info) { - if (!this.world.isClient) { + if (!this.getWorld().isClient) { return; } ToroHealth.HUD.setEntity(ToroHealth.RAYTRACE.getEntityInCrosshair(0, ToroHealth.CONFIG.hud.distance)); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 43a791d..5e659e4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,9 +27,9 @@ "modmenu": "*" }, "depends": { - "fabricloader": ">=0.14.18", + "fabricloader": ">=0.14.21", "fabric": "*", - "minecraft": "1.19.x", + "minecraft": "1.20.x", "java": ">=17" } } From 2c41c443f625d259351c93ff29bf4fd1c017226c Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 6 Jul 2023 00:45:44 +0530 Subject: [PATCH 05/11] Update to Minecraft 1.20.1 (part 2) Passthrough VertexConsumerProvider where needed. --- .../torohealth/bars/HealthBarRenderer.java | 26 ++++++++++++------- .../torohealth/bars/ParticleRenderer.java | 9 ++++--- .../torohealth/display/BarDisplay.java | 2 +- .../torohealth/mixin/WorldRendererMixin.java | 10 +++---- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index 1d19463..f33a8c2 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; @@ -70,7 +72,8 @@ public static void prepareRenderInWorld(LivingEntity entity) { } - public static void renderInWorld(MatrixStack matrix, Camera camera) { + public static void renderInWorld(MatrixStack matrix, + VertexConsumerProvider vertexConsumerProvider, Camera camera) { MinecraftClient client = MinecraftClient.getInstance(); @@ -114,7 +117,7 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) { matrix.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); matrix.scale(-scaleToGui, -scaleToGui, scaleToGui); - render(matrix, entity, 0, 0, FULL_SIZE, true); + render(matrix, vertexConsumerProvider, entity, 0, 0, FULL_SIZE, true); matrix.pop(); } @@ -124,8 +127,9 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) { renderedEntities.clear(); } - public static void render(MatrixStack matrix, LivingEntity entity, double x, double y, - float width, boolean inWorld) { + public static void render(MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, + LivingEntity entity, double x, double y, + float width, boolean inWorld) { Relation relation = EntityUtil.determineRelation(entity); @@ -148,15 +152,16 @@ public static void render(MatrixStack matrix, LivingEntity entity, double x, dou if (!inWorld) { if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.CUMULATIVE)) { - drawDamageNumber(matrix, state.lastDmgCumulative, x, y, width); + drawDamageNumber(matrix, vertexConsumerProvider, state.lastDmgCumulative, x, y, width); } else if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.LAST)) { - drawDamageNumber(matrix, state.lastDmg, x, y, width); + drawDamageNumber(matrix, vertexConsumerProvider, state.lastDmg, x, y, width); } } } - public static void drawDamageNumber(MatrixStack matrix, int dmg, double x, double y, - float width) { + public static void drawDamageNumber(MatrixStack matrix, + VertexConsumerProvider vertexConsumerProvider, + int dmg, double x, double y, float width) { int i = Math.abs(Math.round(dmg)); if (i == 0) { return; @@ -165,7 +170,10 @@ public static void drawDamageNumber(MatrixStack matrix, int dmg, double x, doubl MinecraftClient minecraft = MinecraftClient.getInstance(); int sw = minecraft.textRenderer.getWidth(s); int color = dmg < 0 ? ToroHealth.CONFIG.particle.healColor : ToroHealth.CONFIG.particle.damageColor; - minecraft.textRenderer.draw(matrix, s, (int) (x + (width / 2) - sw), (int) y + 5, color); + minecraft.textRenderer.draw( + s, (float) (x + (width / 2) - sw), (float) y + 5, color, false, + matrix.peek().getPositionMatrix(), vertexConsumerProvider, + TextRenderer.TextLayerType.NORMAL, 0, 0); } private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float percent, diff --git a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java index 6e0c815..564132e 100644 --- a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RotationAxis; @@ -13,13 +14,13 @@ public class ParticleRenderer { - public static void renderParticles(MatrixStack matrix, Camera camera) { + public static void renderParticles(MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, Camera camera) { for (BarParticle p : BarStates.PARTICLES) { - renderParticle(matrix, p, camera); + renderParticle(matrix, vertexConsumerProvider, p, camera); } } - private static void renderParticle(MatrixStack matrix, BarParticle particle, Camera camera) { + private static void renderParticle(MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, BarParticle particle, Camera camera) { double distanceSquared = camera.getPos().squaredDistanceTo(particle.x, particle.y, particle.z); if (distanceSquared > ToroHealth.CONFIG.particle.distanceSquared) { return; @@ -51,7 +52,7 @@ private static void renderParticle(MatrixStack matrix, BarParticle particle, Cam RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - HealthBarRenderer.drawDamageNumber(matrix, particle.damage, 0, 0, 10); + HealthBarRenderer.drawDamageNumber(matrix, vertexConsumerProvider, particle.damage, 0, 0, 10); RenderSystem.disableBlend(); diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index 0c712aa..2d17fe3 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -30,7 +30,7 @@ public void draw(DrawContext drawContext, LivingEntity entity) { RenderSystem.setShaderTexture(0, ICON_TEXTURES); RenderSystem.enableBlend(); - HealthBarRenderer.render(drawContext, entity, 63, 14, 130, false); + HealthBarRenderer.render(drawContext.getMatrices(), drawContext.getVertexConsumers(), entity, 63, 14, 130, false); String name = getEntityName(entity); int healthMax = MathHelper.ceil(entity.getMaxHealth()); int healthCur = Math.min(MathHelper.ceil(entity.getHealth()), healthMax); diff --git a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java index ef44f10..1fb78cc 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java @@ -1,17 +1,18 @@ package net.torocraft.torohealth.mixin; +import net.minecraft.client.render.BufferBuilderStorage; import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.torocraft.torohealth.bars.HealthBarRenderer; import net.torocraft.torohealth.bars.ParticleRenderer; import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -21,8 +22,7 @@ @Mixin(WorldRenderer.class) public class WorldRendererMixin { - @Shadow - private EntityRenderDispatcher entityRenderDispatcher; + @Shadow @Final private BufferBuilderStorage bufferBuilders; @Inject(method = "renderEntity", at = @At(value = "RETURN")) private void renderEntity(Entity entity, double x, double y, double z, float g, @@ -36,8 +36,8 @@ private void renderEntity(Entity entity, double x, double y, double z, float g, private void render(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix, CallbackInfo info) { - HealthBarRenderer.renderInWorld(matrices, camera); - ParticleRenderer.renderParticles(matrices, camera); + HealthBarRenderer.renderInWorld(matrices, this.bufferBuilders.getEntityVertexConsumers(), camera); + ParticleRenderer.renderParticles(matrices, this.bufferBuilders.getEntityVertexConsumers(), camera); } } From 9abb6a053a59ecb6e1304b97852eac9c67c8d182 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 15:28:37 +0530 Subject: [PATCH 06/11] Fix damage particle colours, bump version --- gradle.properties | 2 +- .../java/net/torocraft/torohealth/bars/HealthBarRenderer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 449ed75..2da88e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,6 @@ loader_version=0.14.21 fabric_version=0.84.0+1.20.1 # Mod Properties -mod_version = 1.20.1-fabric-1 +mod_version = 1.20.1-fabric-2 maven_group = net.torocraft archives_base_name = torohealth diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index f33a8c2..bc9ae68 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -173,7 +173,7 @@ public static void drawDamageNumber(MatrixStack matrix, minecraft.textRenderer.draw( s, (float) (x + (width / 2) - sw), (float) y + 5, color, false, matrix.peek().getPositionMatrix(), vertexConsumerProvider, - TextRenderer.TextLayerType.NORMAL, 0, 0); + TextRenderer.TextLayerType.NORMAL, 0, 15728880); } private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float percent, From 4dd329ff7276fb033e4e89ea3668abdbc4536ab6 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Mon, 30 Oct 2023 02:55:58 +0530 Subject: [PATCH 07/11] Update to Minecraft 1.20.2 - Fix F3 debug HUD detection. - Handle new split textures correctly. - Update Gradle, Loom, FLoader/FAPI, Yarn. --- build.gradle | 22 ++++++++++++------- gradle.properties | 10 ++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../torohealth/display/BarDisplay.java | 8 +++---- .../net/torocraft/torohealth/display/Hud.java | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index da188b8..7427f6f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.4-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group +base { + archivesName = project.archives_base_name +} + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -19,7 +19,7 @@ repositories { } dependencies { - //to change the versions see the gradle.properties file + // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" @@ -27,6 +27,10 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Uncomment the following line to enable the deprecated Fabric API modules. + // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. + + // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" } processResources { @@ -38,7 +42,6 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 } @@ -47,11 +50,14 @@ java { // if it is present. // If you remove this line, sources will not be generated. withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${project.base.archivesName.get()}"} } } diff --git a/gradle.properties b/gradle.properties index 2da88e4..d5cede5 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.20.1 -yarn_mappings=1.20.1+build.8 -loader_version=0.14.21 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.4 +loader_version=0.14.24 #Fabric api -fabric_version=0.84.0+1.20.1 +fabric_version=0.90.4+1.20.2 # Mod Properties -mod_version = 1.20.1-fabric-2 +mod_version = 1.20.2-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 1e836ab..15bc934 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-8.1.1-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index 2d17fe3..278b474 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -11,7 +11,8 @@ public class BarDisplay { - private static final Identifier ICON_TEXTURES = new Identifier("textures/gui/icons.png"); + private static final Identifier ARMOR_TEXTURE = new Identifier("hud/armor_full"); + private static final Identifier HEART_TEXTURE = new Identifier("hud/heart/full"); private final MinecraftClient mc; public BarDisplay(MinecraftClient mc) { @@ -27,7 +28,6 @@ public void draw(DrawContext drawContext, LivingEntity entity) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderTexture(0, ICON_TEXTURES); RenderSystem.enableBlend(); HealthBarRenderer.render(drawContext.getMatrices(), drawContext.getVertexConsumers(), entity, 63, 14, 130, false); @@ -58,10 +58,10 @@ public void draw(DrawContext drawContext, LivingEntity entity) { } private void renderArmorIcon(DrawContext drawContext, int x, int y) { - drawContext.drawTexture(ICON_TEXTURES, x, y, 34, 9, 9, 9); + drawContext.drawGuiTexture(ARMOR_TEXTURE, x, y, 9, 9); } private void renderHeartIcon(DrawContext drawContext, int x, int y) { - drawContext.drawTexture(ICON_TEXTURES, x, y, 16 + 36, 0, 9, 9); + drawContext.drawGuiTexture(HEART_TEXTURE, x, y, 9, 9); } } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index dee3222..17e15ab 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -28,7 +28,7 @@ public Hud() { } public void draw(DrawContext drawContext, Config config) { - if (this.client.options.debugEnabled) { + if (this.client.getDebugHud().shouldShowDebugHud()) { return; } this.config = config; From 73fad3639381db1b27aa5afbc09448c90ee2409b Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 03:17:11 +0530 Subject: [PATCH 08/11] Update to Minecraft 1.20.5/1.20.6 - Use FAPI's WorldRenderEvents instead of custom mixin (we already depend on FAPI). - Adapt to minor API changes. - Require Java 21 as the baseline. - Update Gradle, Loom, FLoader/FAPI, Yarn. --- build.gradle | 8 ++++---- gradle.properties | 10 +++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../java/net/torocraft/torohealth/ToroHealth.java | 11 +++++++++++ .../torocraft/torohealth/display/EntityDisplay.java | 9 +++++---- .../torohealth/mixin/WorldRendererAccessor.java | 11 +++++++++++ .../torohealth/mixin/WorldRendererMixin.java | 13 +++---------- .../net/torocraft/torohealth/util/EntityUtil.java | 4 ++-- src/main/resources/fabric.mod.json | 2 +- src/main/resources/torohealth.mixins.json | 5 +++-- 10 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/torocraft/torohealth/mixin/WorldRendererAccessor.java diff --git a/build.gradle b/build.gradle index 7427f6f..2ca38c5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4-SNAPSHOT' + id 'fabric-loom' version '1.8-SNAPSHOT' id 'maven-publish' } @@ -42,7 +42,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 17 + it.options.release = 21 } java { @@ -51,8 +51,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { diff --git a/gradle.properties b/gradle.properties index d5cede5..e0d4ab0 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.20.2 -yarn_mappings=1.20.2+build.4 -loader_version=0.14.24 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.3 +loader_version=0.16.9 #Fabric api -fabric_version=0.90.4+1.20.2 +fabric_version=0.100.8+1.20.6 # Mod Properties -mod_version = 1.20.2-fabric-1 +mod_version = 1.20.5-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 15bc934..9851827 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-8.4-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/torocraft/torohealth/ToroHealth.java b/src/main/java/net/torocraft/torohealth/ToroHealth.java index 322f6ff..8fea6dd 100644 --- a/src/main/java/net/torocraft/torohealth/ToroHealth.java +++ b/src/main/java/net/torocraft/torohealth/ToroHealth.java @@ -2,9 +2,13 @@ import java.util.Random; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.torocraft.torohealth.bars.HealthBarRenderer; +import net.torocraft.torohealth.bars.ParticleRenderer; import net.torocraft.torohealth.config.Config; import net.torocraft.torohealth.config.loader.ConfigLoader; import net.torocraft.torohealth.display.Hud; +import net.torocraft.torohealth.mixin.WorldRendererAccessor; import net.torocraft.torohealth.util.RayTrace; public class ToroHealth implements ModInitializer { @@ -24,5 +28,12 @@ public class ToroHealth implements ModInitializer { @Override public void onInitialize() { CONFIG_LOADER.load(); + WorldRenderEvents.LAST.register((context) -> { + var entityVertexConsumers = ((WorldRendererAccessor) context.worldRenderer()) + .getBufferBuilders() + .getEntityVertexConsumers(); + HealthBarRenderer.renderInWorld(context.matrixStack(), entityVertexConsumers, context.camera()); + ParticleRenderer.renderParticles(context.matrixStack(), entityVertexConsumers, context.camera()); + }); } } diff --git a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java index 97b1fca..67912e2 100644 --- a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java @@ -12,6 +12,7 @@ import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RotationAxis; +import org.joml.Matrix4fStack; import org.joml.Quaternionf; public class EntityDisplay { @@ -74,9 +75,9 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, float mouseY, LivingEntity entity, float scale) { float f = (float) Math.atan((double) (mouseX / 40.0F)); float g = (float) Math.atan((double) (mouseY / 40.0F)); - MatrixStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.push(); - matrixStack.translate((double) x * scale, (double) y * scale, 1050.0D * scale); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.pushMatrix(); + matrixStack.translate(x * scale, y * scale, 1050.0F * scale); matrixStack.scale(1.0F, 1.0F, -1.0F); RenderSystem.applyModelViewMatrix(); matrixStack2.push(); @@ -114,7 +115,7 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, entity.setPitch(j); entity.prevHeadYaw = k; entity.headYaw = l; - matrixStack.pop(); + matrixStack.popMatrix(); matrixStack2.pop(); RenderSystem.applyModelViewMatrix(); DiffuseLighting.enableGuiDepthLighting(); diff --git a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererAccessor.java b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererAccessor.java new file mode 100644 index 0000000..371fb56 --- /dev/null +++ b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererAccessor.java @@ -0,0 +1,11 @@ +package net.torocraft.torohealth.mixin; + +import net.minecraft.client.render.BufferBuilderStorage; +import net.minecraft.client.render.WorldRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(WorldRenderer.class) +public interface WorldRendererAccessor { + @Accessor BufferBuilderStorage getBufferBuilders(); +} diff --git a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java index 1fb78cc..8963908 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/WorldRendererMixin.java @@ -1,20 +1,12 @@ package net.torocraft.torohealth.mixin; -import net.minecraft.client.render.BufferBuilderStorage; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.torocraft.torohealth.bars.HealthBarRenderer; -import net.torocraft.torohealth.bars.ParticleRenderer; -import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -22,7 +14,7 @@ @Mixin(WorldRenderer.class) public class WorldRendererMixin { - @Shadow @Final private BufferBuilderStorage bufferBuilders; + // @Shadow @Final private BufferBuilderStorage bufferBuilders; @Inject(method = "renderEntity", at = @At(value = "RETURN")) private void renderEntity(Entity entity, double x, double y, double z, float g, @@ -32,12 +24,13 @@ private void renderEntity(Entity entity, double x, double y, double z, float g, } } + /* Replaced by WorldRenderEvents.LAST event listener registered in ToroHealth.java @Inject(method = "render", at = @At(value = "RETURN")) private void render(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix, CallbackInfo info) { HealthBarRenderer.renderInWorld(matrices, this.bufferBuilders.getEntityVertexConsumers(), camera); ParticleRenderer.renderParticles(matrices, this.bufferBuilders.getEntityVertexConsumers(), camera); - } + } */ } diff --git a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java index ad11d0d..1f8629c 100644 --- a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java +++ b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java @@ -44,13 +44,13 @@ public static Relation determineRelation(Entity entity) { } public static boolean showHealthBar(Entity entity, MinecraftClient client) { - return entity instanceof LivingEntity + return entity instanceof LivingEntity living && !(entity instanceof ArmorStandEntity) && (!entity.isInvisibleTo(client.player) || entity.isGlowing() || entity.isOnFire() || entity instanceof CreeperEntity && ((CreeperEntity) entity).shouldRenderOverlay() // charged creeper - || StreamSupport.stream(entity.getItemsEquipped().spliterator(), false).anyMatch(is -> !is.isEmpty())) + || StreamSupport.stream(living.getEquippedItems().spliterator(), false).anyMatch(is -> !is.isEmpty())) && entity != client.player && !entity.isSpectator(); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5e659e4..8ad2af1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,6 +30,6 @@ "fabricloader": ">=0.14.21", "fabric": "*", "minecraft": "1.20.x", - "java": ">=17" + "java": ">=21" } } diff --git a/src/main/resources/torohealth.mixins.json b/src/main/resources/torohealth.mixins.json index 4b498d8..cfc24e3 100644 --- a/src/main/resources/torohealth.mixins.json +++ b/src/main/resources/torohealth.mixins.json @@ -7,9 +7,10 @@ "client": [ "InGameHudMixin", "PlayerEntityMixin", - "WorldRendererMixin" + "WorldRendererMixin", + "WorldRendererAccessor" ], "injectors": { "defaultRequire": 1 } -} \ No newline at end of file +} From 405f5b35aa7764bd9575be9fd3d63de5144f0edb Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 03:37:32 +0530 Subject: [PATCH 09/11] Update to Minecraft 1.21/1.21.1 - Adapt to minor API changes. - Update Gradle, Loom, FLoader/FAPI, Yarn. --- gradle.properties | 8 ++++---- .../torohealth/bars/HealthBarRenderer.java | 18 +++++++++--------- .../torohealth/bars/ParticleRenderer.java | 2 +- .../torohealth/display/BarDisplay.java | 4 ++-- .../net/torocraft/torohealth/display/Hud.java | 2 +- .../torohealth/mixin/InGameHudMixin.java | 3 ++- src/main/resources/fabric.mod.json | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index e0d4ab0..d79444f 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.20.6 -yarn_mappings=1.20.6+build.3 +minecraft_version=1.21.1 +yarn_mappings=1.21.1+build.3 loader_version=0.16.9 #Fabric api -fabric_version=0.100.8+1.20.6 +fabric_version=0.110.0+1.21.1 # Mod Properties -mod_version = 1.20.5-fabric-1 +mod_version = 1.21.1-fabric-1 maven_group = net.torocraft archives_base_name = torohealth diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index bc9ae68..0e54c14 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; @@ -29,7 +30,7 @@ public class HealthBarRenderer { - private static final Identifier GUI_BARS_TEXTURES = new Identifier(ToroHealth.MODID + ":textures/gui/bars.png"); + private static final Identifier GUI_BARS_TEXTURES = Identifier.of(ToroHealth.MODID + ":textures/gui/bars.png"); private static final int DARK_GRAY = 0x808080; private static final float FULL_SIZE = 40; @@ -101,7 +102,7 @@ public static void renderInWorld(MatrixStack matrix, boolean sneaking = entity.isInSneakingPose(); float height = entity.getHeight() + 0.6F - (sneaking ? 0.25F : 0.0F); - float tickDelta = client.getTickDelta(); + float tickDelta = client.getRenderTickCounter().getTickDelta(true); double x = MathHelper.lerp((double) tickDelta, entity.prevX, entity.getX()); double y = MathHelper.lerp((double) tickDelta, entity.prevY, entity.getY()); double z = MathHelper.lerp((double) tickDelta, entity.prevZ, entity.getZ()); @@ -201,16 +202,15 @@ private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float zOffsetAmount = inWorld ? -0.1F : 0.1F; Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); + BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); buffer.vertex(matrix4f, (float) (-half + x), (float) y, zOffset * zOffsetAmount) - .texture(u * c, v * c).next(); + .texture(u * c, v * c); buffer.vertex(matrix4f, (float) (-half + x), (float) (h + y), zOffset * zOffsetAmount) - .texture(u * c, (v + vh) * c).next(); + .texture(u * c, (v + vh) * c); buffer.vertex(matrix4f, (float) (-half + size + x), (float) (h + y), zOffset * zOffsetAmount) - .texture((u + uw) * c, (v + vh) * c).next(); + .texture((u + uw) * c, (v + vh) * c); buffer.vertex(matrix4f, (float) (-half + size + x), (float) y, zOffset * zOffsetAmount) - .texture(((u + uw) * c), v * c).next(); - tessellator.draw(); + .texture(((u + uw) * c), v * c); + BufferRenderer.drawWithGlobalProgram(buffer.end()); } } diff --git a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java index 564132e..f06eb57 100644 --- a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java @@ -29,7 +29,7 @@ private static void renderParticle(MatrixStack matrix, VertexConsumerProvider ve float scaleToGui = 0.025f; MinecraftClient client = MinecraftClient.getInstance(); - float tickDelta = client.getTickDelta(); + float tickDelta = client.getRenderTickCounter().getTickDelta(true); double x = MathHelper.lerp((double) tickDelta, particle.xPrev, particle.x); double y = MathHelper.lerp((double) tickDelta, particle.yPrev, particle.y); diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index 278b474..e1a5098 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -11,8 +11,8 @@ public class BarDisplay { - private static final Identifier ARMOR_TEXTURE = new Identifier("hud/armor_full"); - private static final Identifier HEART_TEXTURE = new Identifier("hud/heart/full"); + private static final Identifier ARMOR_TEXTURE = Identifier.of("hud/armor_full"); + private static final Identifier HEART_TEXTURE = Identifier.of("hud/heart/full"); private final MinecraftClient mc; public BarDisplay(MinecraftClient mc) { diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index 17e15ab..69eccb5 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -14,7 +14,7 @@ public class Hud extends Screen { private static final Identifier BACKGROUND_TEXTURE = - new Identifier(ToroHealth.MODID + ":textures/gui/default_skin_basic.png"); + Identifier.of(ToroHealth.MODID + ":textures/gui/default_skin_basic.png"); private EntityDisplay entityDisplay = new EntityDisplay(); private LivingEntity entity; private BarDisplay barDisplay; diff --git a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java index 1a43eb7..352381b 100644 --- a/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java +++ b/src/main/java/net/torocraft/torohealth/mixin/InGameHudMixin.java @@ -2,6 +2,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.client.render.RenderTickCounter; import net.torocraft.torohealth.ToroHealth; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,7 +13,7 @@ public class InGameHudMixin { @Inject(method = "render", at = @At("RETURN")) - private void render(DrawContext drawContext, float partial, CallbackInfo info) { + private void render(DrawContext drawContext, RenderTickCounter tickCounter, CallbackInfo ci) { ToroHealth.HUD.draw(drawContext, ToroHealth.CONFIG); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8ad2af1..0d2d3ad 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "depends": { "fabricloader": ">=0.14.21", "fabric": "*", - "minecraft": "1.20.x", + "minecraft": "1.21.x", "java": ">=21" } } From cc18f803278c4c8e00ec66b856a0cb5ad63fdcf4 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 15:22:14 +0530 Subject: [PATCH 10/11] WIP: Update to Minecraft 1.21.2/1.21.3 - Adapt to minor API changes. - Update Gradle, Loom, FLoader/FAPI, Yarn. --- gradle.properties | 8 ++++---- .../net/torocraft/torohealth/bars/HealthBarRenderer.java | 6 +++--- .../net/torocraft/torohealth/bars/ParticleRenderer.java | 4 ++-- .../net/torocraft/torohealth/display/BarDisplay.java | 9 +++++---- src/main/java/net/torocraft/torohealth/display/Hud.java | 3 ++- .../java/net/torocraft/torohealth/util/EntityUtil.java | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gradle.properties b/gradle.properties index d79444f..a7589dd 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.21.1 -yarn_mappings=1.21.1+build.3 +minecraft_version=1.21.3 +yarn_mappings=1.21.3+build.2 loader_version=0.16.9 #Fabric api -fabric_version=0.110.0+1.21.1 +fabric_version=0.110.0+1.21.3 # Mod Properties -mod_version = 1.21.1-fabric-1 +mod_version = 1.21.3-fabric-1 maven_group = net.torocraft archives_base_name = torohealth diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index 0e54c14..d7e636d 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -5,10 +5,10 @@ import java.util.List; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Camera; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexFormat; @@ -91,7 +91,7 @@ public static void renderInWorld(MatrixStack matrix, return; } - RenderSystem.setShader(GameRenderer::getPositionColorProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); RenderSystem.enableDepthTest(); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, @@ -193,7 +193,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::getPositionTexProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX); 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 f06eb57..c7b3f12 100644 --- a/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java @@ -2,8 +2,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.render.Camera; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; @@ -46,7 +46,7 @@ private static void renderParticle(MatrixStack matrix, VertexConsumerProvider ve matrix.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); matrix.scale(-scaleToGui, -scaleToGui, scaleToGui); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); 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 e1a5098..beec3ac 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -2,8 +2,9 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.RenderLayer; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -27,7 +28,7 @@ public void draw(DrawContext drawContext, LivingEntity entity) { int xOffset = 0; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShader(GameRenderer::getPositionTexProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX); RenderSystem.enableBlend(); HealthBarRenderer.render(drawContext.getMatrices(), drawContext.getVertexConsumers(), entity, 63, 14, 130, false); @@ -58,10 +59,10 @@ public void draw(DrawContext drawContext, LivingEntity entity) { } private void renderArmorIcon(DrawContext drawContext, int x, int y) { - drawContext.drawGuiTexture(ARMOR_TEXTURE, x, y, 9, 9); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, ARMOR_TEXTURE, x, y, 9, 9); } private void renderHeartIcon(DrawContext drawContext, int x, int y) { - drawContext.drawGuiTexture(HEART_TEXTURE, x, y, 9, 9); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, HEART_TEXTURE, x, y, 9, 9); } } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index 69eccb5..c4add5c 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.text.*; @@ -129,6 +130,6 @@ private void draw(DrawContext drawContext, float x, float y, float scale) { private void drawSkin(DrawContext drawContext) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int w = 160, h = 60; - drawContext.drawTexture(BACKGROUND_TEXTURE, 0, 0, 0.0f, 0.0f, w, h, w, h); + drawContext.drawTexture(RenderLayer::getGuiTextured, BACKGROUND_TEXTURE, 0, 0, 0.0f, 0.0f, w, h, w, h); } } diff --git a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java index 1f8629c..19a62bc 100644 --- a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java +++ b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java @@ -49,7 +49,7 @@ public static boolean showHealthBar(Entity entity, MinecraftClient client) { && (!entity.isInvisibleTo(client.player) || entity.isGlowing() || entity.isOnFire() - || entity instanceof CreeperEntity && ((CreeperEntity) entity).shouldRenderOverlay() // charged creeper + || entity instanceof CreeperEntity && ((CreeperEntity) entity).isCharged() // charged creeper || StreamSupport.stream(living.getEquippedItems().spliterator(), false).anyMatch(is -> !is.isEmpty())) && entity != client.player && !entity.isSpectator(); From b38298491b420bad092549a47fdf75d7f216a823 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Thu, 5 Dec 2024 15:23:03 +0530 Subject: [PATCH 11/11] WIP: Experimental patches for 1.21.2/1.21.3 --- .../torohealth/display/BarDisplay.java | 4 +++- .../torohealth/display/EntityDisplay.java | 21 +++++++------------ .../net/torocraft/torohealth/display/Hud.java | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java index beec3ac..ed44572 100644 --- a/src/main/java/net/torocraft/torohealth/display/BarDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/BarDisplay.java @@ -31,7 +31,9 @@ public void draw(DrawContext drawContext, LivingEntity entity) { RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX); RenderSystem.enableBlend(); - HealthBarRenderer.render(drawContext.getMatrices(), drawContext.getVertexConsumers(), entity, 63, 14, 130, false); + drawContext.draw(vertexConsumerProvider -> { + HealthBarRenderer.render(drawContext.getMatrices(), vertexConsumerProvider, entity, 63, 14, 130, false); + }); String name = getEntityName(entity); int healthMax = MathHelper.ceil(entity.getMaxHealth()); int healthCur = Math.min(MathHelper.ceil(entity.getHealth()), healthMax); diff --git a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java index 67912e2..03d45ee 100644 --- a/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java +++ b/src/main/java/net/torocraft/torohealth/display/EntityDisplay.java @@ -2,8 +2,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.DiffuseLighting; -import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; @@ -33,10 +33,10 @@ public void setEntity(LivingEntity entity) { updateScale(); } - public void draw(MatrixStack matrix, float scale) { + public void draw(DrawContext drawContext, MatrixStack matrix, float scale) { if (entity != null) { try { - drawEntity(matrix, (int) xOffset, (int) yOffset, entityScale, -80, -20, entity, scale); + drawEntity(drawContext, matrix, (int) xOffset, (int) yOffset, entityScale, -80, -20, entity, scale); } catch (Exception e) { e.printStackTrace(); } @@ -71,15 +71,14 @@ private void updateScale() { /** * copied from InventoryScreen.drawEntity() to expose the matrixStack */ - public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, float mouseX, - float mouseY, LivingEntity entity, float scale) { + public static void drawEntity(DrawContext drawContext, MatrixStack matrixStack2, int x, int y, int size, + float mouseX, float mouseY, LivingEntity entity, float scale) { float f = (float) Math.atan((double) (mouseX / 40.0F)); float g = (float) Math.atan((double) (mouseY / 40.0F)); Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); matrixStack.pushMatrix(); matrixStack.translate(x * scale, y * scale, 1050.0F * scale); matrixStack.scale(1.0F, 1.0F, -1.0F); - RenderSystem.applyModelViewMatrix(); matrixStack2.push(); matrixStack2.translate(0.0D, 0.0D, 1000.0D); matrixStack2.scale((float) size, (float) size, (float) size); @@ -102,13 +101,10 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, quaternion2.conjugate(); entityRenderDispatcher.setRotation(quaternion2); entityRenderDispatcher.setRenderShadows(false); - VertexConsumerProvider.Immediate immediate = - MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(); - RenderSystem.runAsFancy(() -> { - entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, matrixStack2, immediate, - 15728880); + drawContext.draw(vertexConsumerProvider -> { + entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 1.0F, matrixStack2, + vertexConsumerProvider, 15728880); }); - immediate.draw(); entityRenderDispatcher.setRenderShadows(true); entity.bodyYaw = h; entity.setYaw(i); @@ -117,7 +113,6 @@ public static void drawEntity(MatrixStack matrixStack2, int x, int y, int size, entity.headYaw = l; matrixStack.popMatrix(); matrixStack2.pop(); - RenderSystem.applyModelViewMatrix(); DiffuseLighting.enableGuiDepthLighting(); } diff --git a/src/main/java/net/torocraft/torohealth/display/Hud.java b/src/main/java/net/torocraft/torohealth/display/Hud.java index c4add5c..1d6ef9e 100644 --- a/src/main/java/net/torocraft/torohealth/display/Hud.java +++ b/src/main/java/net/torocraft/torohealth/display/Hud.java @@ -118,7 +118,7 @@ private void draw(DrawContext drawContext, float x, float y, float scale) { } matrix.translate(10, 10, 0); if (config.hud.showEntity) { - entityDisplay.draw(matrix, scale); + entityDisplay.draw(drawContext, matrix, scale); } matrix.translate(44, 0, 0); if (config.hud.showBar) {