Skip to content

Commit 6644fdd

Browse files
committed
Update to 1.21
1 parent 9beec6c commit 6644fdd

File tree

7 files changed

+53
-46
lines changed

7 files changed

+53
-46
lines changed

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
plugins {
2-
id 'fabric-loom' version '1.2-SNAPSHOT'
2+
id 'fabric-loom' version '1.7-SNAPSHOT'
33
}
44

5-
sourceCompatibility = JavaVersion.VERSION_17
6-
targetCompatibility = JavaVersion.VERSION_17
7-
8-
archivesBaseName = project.archives_base_name
95
version = "${project.mod_version}-${project.minecraft_version}"
106

7+
base {
8+
archivesBaseName = project.archives_base_name
9+
}
10+
1111
repositories {
1212

1313
}
@@ -29,11 +29,14 @@ processResources {
2929
}
3030

3131
tasks.withType(JavaCompile).configureEach {
32-
it.options.release = 17
32+
it.options.release = 21
3333
}
3434

3535
java {
3636
withSourcesJar()
37+
38+
sourceCompatibility = JavaVersion.VERSION_21
39+
targetCompatibility = JavaVersion.VERSION_21
3740
}
3841

3942
jar {

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
5-
minecraft_version=1.20.1
6-
yarn_mappings=1.20.1+build.1
7-
loader_version=0.14.21
5+
minecraft_version=1.21
6+
yarn_mappings=1.21+build.9
7+
loader_version=0.15.11
88

99
# Mod Properties
1010
mod_version = 1.1.0
1111
archives_base_name = PlayerHealthIndicators
1212

1313
# Dependencies
14-
fabric_version=0.83.1+1.20.1
14+
fabric_version=0.100.7+1.21
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package me.andrew.healthindicators;
22

3+
import net.minecraft.util.Identifier;
4+
35
public enum HeartType {
4-
EMPTY(16 + 0 * 9, 0),
5-
RED_FULL(16 + 4 * 9, 0),
6-
RED_HALF(16 + 5 * 9, 0),
7-
YELLOW_FULL(16 + 16 * 9, 0),
8-
YELLOW_HALF(16 + 17 * 9, 0);
6+
EMPTY(Identifier.ofVanilla("hud/heart/container")),
7+
RED_FULL(Identifier.ofVanilla("hud/heart/full")),
8+
RED_HALF(Identifier.ofVanilla("hud/heart/half")),
9+
YELLOW_FULL(Identifier.ofVanilla("hud/heart/absorbing_full")),
10+
YELLOW_HALF(Identifier.ofVanilla("hud/heart/absorbing_half"));
911

10-
public final int u;
11-
public final int v;
12+
public final Identifier texture;
1213

13-
HeartType(int u, int v) {
14-
this.u = u;
15-
this.v = v;
14+
HeartType(Identifier texture) {
15+
this.texture = texture;
1616
}
1717
}

src/main/java/me/andrew/healthindicators/mixin/PlayerEntityRendererMixin.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
import net.minecraft.client.render.entity.LivingEntityRenderer;
1111
import net.minecraft.client.render.entity.PlayerEntityRenderer;
1212
import net.minecraft.client.render.entity.model.PlayerEntityModel;
13+
import net.minecraft.client.texture.GuiAtlasManager;
14+
import net.minecraft.client.texture.Sprite;
1315
import net.minecraft.client.util.math.MatrixStack;
1416
import net.minecraft.entity.Entity;
15-
import net.minecraft.util.Identifier;
17+
import net.minecraft.scoreboard.ScoreboardDisplaySlot;
1618
import net.minecraft.util.math.MathHelper;
1719
import org.joml.Matrix4f;
1820
import org.spongepowered.asm.mixin.Mixin;
21+
import org.spongepowered.asm.mixin.Unique;
1922
import org.spongepowered.asm.mixin.injection.At;
2023
import org.spongepowered.asm.mixin.injection.Inject;
2124
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2225

2326
@Mixin(PlayerEntityRenderer.class)
2427
public abstract class PlayerEntityRendererMixin extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {
25-
private static final Identifier ICONS = new Identifier("textures/gui/icons.png");
26-
2728
public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntityModel<AbstractClientPlayerEntity> model, float shadowRadius) {
2829
super(ctx, model, shadowRadius);
2930
}
@@ -44,7 +45,7 @@ public void renderHealth(AbstractClientPlayerEntity abstractClientPlayerEntity,
4445
matrixStack.translate(0, abstractClientPlayerEntity.getHeight() + 0.5f, 0);
4546
if (this.hasLabel(abstractClientPlayerEntity) && d <= 4096.0) {
4647
matrixStack.translate(0.0D, 9.0F * 1.15F * 0.025F, 0.0D);
47-
if (d < 100.0 && abstractClientPlayerEntity.getScoreboard().getObjectiveForSlot(2) != null) {
48+
if (d < 100.0 && abstractClientPlayerEntity.getScoreboard().getObjectiveForSlot(ScoreboardDisplaySlot.BELOW_NAME) != null) {
4849
matrixStack.translate(0.0D, 9.0F * 1.15F * 0.025F, 0.0D);
4950
}
5051
}
@@ -56,13 +57,12 @@ public void renderHealth(AbstractClientPlayerEntity abstractClientPlayerEntity,
5657
matrixStack.scale(pixelSize, pixelSize, pixelSize);
5758
matrixStack.translate(0, Config.getHeartOffset(), 0);
5859

59-
Tessellator tessellator = Tessellator.getInstance();
60-
BufferBuilder vertexConsumer = tessellator.getBuffer();
60+
GuiAtlasManager guiAtlasManager = MinecraftClient.getInstance().getGuiAtlasManager();
6161

62-
vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
6362
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
64-
RenderSystem.setShaderTexture(0, ICONS);
63+
RenderSystem.setShaderTexture(0, guiAtlasManager.getSprite(HeartType.EMPTY.texture).getAtlasId());
6564
RenderSystem.enableDepthTest();
65+
BufferBuilder vertexConsumer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
6666

6767
Matrix4f model = matrixStack.peek().getPositionMatrix();
6868

@@ -90,7 +90,7 @@ public void renderHealth(AbstractClientPlayerEntity abstractClientPlayerEntity,
9090
float x = maxX - col * 8;
9191
float y = row * rowOffset;
9292
float z = row * 0.01F;
93-
drawHeart(model, vertexConsumer, x, y, z, HeartType.EMPTY);
93+
drawHeart(model, vertexConsumer, x, y, z, HeartType.EMPTY, guiAtlasManager);
9494

9595
HeartType type;
9696
if (heart < heartsRed) {
@@ -107,15 +107,16 @@ public void renderHealth(AbstractClientPlayerEntity abstractClientPlayerEntity,
107107
}
108108
}
109109
if (type != HeartType.EMPTY) {
110-
drawHeart(model, vertexConsumer, x, y, z, type);
110+
drawHeart(model, vertexConsumer, x, y, z, type, guiAtlasManager);
111111
}
112112
}
113113

114-
tessellator.draw();
114+
BufferRenderer.drawWithGlobalProgram(vertexConsumer.end());
115115

116116
matrixStack.pop();
117117
}
118118

119+
@Unique
119120
private static boolean shouldRenderHeartsForEntity(Entity entity) {
120121
if (entity instanceof AbstractClientPlayerEntity abstractClientPlayerEntity) {
121122
return !abstractClientPlayerEntity.isMainPlayer() && !abstractClientPlayerEntity.isInvisibleTo(MinecraftClient.getInstance().player);
@@ -124,21 +125,25 @@ private static boolean shouldRenderHeartsForEntity(Entity entity) {
124125
return false;
125126
}
126127

127-
private static void drawHeart(Matrix4f model, VertexConsumer vertexConsumer, float x, float y, float z, HeartType type){
128-
float minU = type.u / 256F;
129-
float maxU = minU + 9F / 256F;
130-
float minV = type.v / 256F;
131-
float maxV = minV + 9F / 256F;
128+
@Unique
129+
private static void drawHeart(Matrix4f model, VertexConsumer vertexConsumer, float x, float y, float z, HeartType type, GuiAtlasManager guiAtlasManager){
130+
Sprite sprite = guiAtlasManager.getSprite(type.texture);
131+
132+
float minU = sprite.getMinU();
133+
float maxU = sprite.getMaxU();
134+
float minV = sprite.getMinV();
135+
float maxV = sprite.getMaxV();
132136

133137
float heartSize = 9F;
134138

135139
drawVertex(model, vertexConsumer, x, y - heartSize, z, minU, maxV);
136-
drawVertex(model, vertexConsumer, x - heartSize, y - heartSize, z, maxU, maxV);
137-
drawVertex(model, vertexConsumer, x - heartSize, y, z, maxU, minV);
138140
drawVertex(model, vertexConsumer, x, y, z, minU, minV);
141+
drawVertex(model, vertexConsumer, x - heartSize, y, z, maxU, minV);
142+
drawVertex(model, vertexConsumer, x - heartSize, y - heartSize, z, maxU, maxV);
139143
}
140144

145+
@Unique
141146
private static void drawVertex(Matrix4f model, VertexConsumer vertices, float x, float y, float z, float u, float v) {
142-
vertices.vertex(model, x, y, z).texture(u, v).next();
147+
vertices.vertex(model, x, y, z).texture(u, v);
143148
}
144149
}

src/main/resources/fabric.mod.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
],
2323

2424
"depends": {
25-
"fabricloader": ">=0.11.3",
26-
"fabric": "*",
27-
"minecraft": "1.20.x",
28-
"java": ">=17"
25+
"fabricloader": ">=0.15.11",
26+
"minecraft": "~1.21",
27+
"java": ">=21",
28+
"fabric-api": "*"
2929
}
3030
}

src/main/resources/healthindicators.mixins.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"required": true,
3-
"minVersion": "0.8",
43
"package": "me.andrew.healthindicators.mixin",
5-
"compatibilityLevel": "JAVA_17",
4+
"compatibilityLevel": "JAVA_21",
65
"client": [
76
"PlayerEntityRendererMixin"
87
],

0 commit comments

Comments
 (0)