Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fabric] Update to Minecraft 1.20.4 #171

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
71 changes: 40 additions & 31 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,70 +1,79 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.8-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
// 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
// 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}"

// 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 {
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 {
it.options.release = 21
}

// 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()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
from "LICENSE"
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}

// 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.
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9

#Fabric api
fabric_version=0.55.2+1.19
fabric_version=0.110.0+1.21.3

# Mod Properties
mod_version = 1.19-fabric-1
mod_version = 1.21.3-fabric-1
maven_group = net.torocraft
archives_base_name = torohealth
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/torocraft/torohealth/ToroHealth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
});
}
}
59 changes: 34 additions & 25 deletions src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@
import java.util.ArrayList;
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;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
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 {

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;

Expand Down Expand Up @@ -70,7 +73,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();

Expand All @@ -87,7 +91,7 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) {
return;
}

RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
RenderSystem.enableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE,
Expand All @@ -98,7 +102,7 @@ public static void renderInWorld(MatrixStack matrix, Camera camera) {
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());
Expand All @@ -110,11 +114,11 @@ 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);
render(matrix, vertexConsumerProvider, entity, 0, 0, FULL_SIZE, true);

matrix.pop();
}
Expand All @@ -124,8 +128,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);

Expand All @@ -144,18 +149,20 @@ 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)) {
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;
Expand All @@ -164,7 +171,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, 15728880);
}

private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float percent,
Expand All @@ -183,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::getPositionTexShader);
RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX);
RenderSystem.setShaderTexture(0, GUI_BARS_TEXTURES);
RenderSystem.enableBlend();

Expand All @@ -192,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());
}
}
21 changes: 11 additions & 10 deletions src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

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;
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;

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;
Expand All @@ -28,7 +29,7 @@ private static void renderParticle(MatrixStack matrix, BarParticle particle, Cam
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);
Expand All @@ -41,17 +42,17 @@ 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(ShaderProgramKeys.POSITION_COLOR);
RenderSystem.enableDepthTest();
RenderSystem.enableBlend();
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();

Expand Down
Loading