Skip to content

Commit

Permalink
Update to Minecraft 1.20.5/1.20.6
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
retrixe committed Dec 5, 2024
1 parent 4dd329f commit 73fad36
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -42,7 +42,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
Expand All @@ -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 {
Expand Down
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.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
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-8.4-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
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());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
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;

@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,
Expand All @@ -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);
}
} */

}
4 changes: 2 additions & 2 deletions src/main/java/net/torocraft/torohealth/util/EntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"fabricloader": ">=0.14.21",
"fabric": "*",
"minecraft": "1.20.x",
"java": ">=17"
"java": ">=21"
}
}
5 changes: 3 additions & 2 deletions src/main/resources/torohealth.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"client": [
"InGameHudMixin",
"PlayerEntityMixin",
"WorldRendererMixin"
"WorldRendererMixin",
"WorldRendererAccessor"
],
"injectors": {
"defaultRequire": 1
}
}
}

0 comments on commit 73fad36

Please sign in to comment.