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 +}