Skip to content

Commit

Permalink
Merge pull request #19 from Provismet/1.20
Browse files Browse the repository at this point in the history
1.2.4 Update
  • Loading branch information
Provismet authored Feb 27, 2024
2 parents 60ab914 + 268b784 commit 86a7e7e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 44 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.15.6

# Mod Properties
mod_version=1.2.3
mod_version=1.2.4
maven_group=com.provismet
archives_base_name=provihealth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.provismet.provihealth.config.Options;
import com.provismet.provihealth.config.Options.DamageParticleType;
import com.provismet.provihealth.config.Options.HUDPortraitCompatMode;
import com.provismet.provihealth.config.Options.HUDPosition;
import com.provismet.provihealth.config.Options.HUDType;
import com.provismet.provihealth.config.Options.SeeThroughText;
Expand Down Expand Up @@ -365,6 +366,12 @@ public static Screen build (Screen parent) {
.build()
);

compatibility.addEntry(entryBuilder.startEnumSelector(Text.translatable("entry.provihealth.compatHud"), HUDPortraitCompatMode.class, Options.HUDCompat)
.setDefaultValue(HUDPortraitCompatMode.STANDARD)
.setSaveConsumer(newValue -> Options.HUDCompat = newValue)
.build()
);

builder.setSavingRunnable(Options::save);
return builder.build();
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/provismet/provihealth/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class Options {
public static SeeThroughText seeThroughTextType = SeeThroughText.STANDARD;
public static boolean compatInWorld = false;
public static boolean compatInHUD = false;
public static HUDPortraitCompatMode HUDCompat = HUDPortraitCompatMode.STANDARD;

@SuppressWarnings("resource")
public static boolean shouldRenderHealthFor (LivingEntity livingEntity) {
Expand Down Expand Up @@ -181,6 +182,7 @@ public static void save () {
.append("maxParticleDistance", maxParticleDistance).newLine()
.append("topLayerTextType", seeThroughTextType.name()).newLine()
.append("compatWorldBar", compatInWorld).newLine()
.append("compatHudPaperdoll", HUDCompat.name()).newLine()
.createArray("healthBlacklist", blacklist).newLine()
.createArray("hudBlacklist", blacklistHUD).newLine(false)
.closeObject()
Expand Down Expand Up @@ -392,6 +394,10 @@ public static void load () {
compatInWorld = parser.nextBoolean();
break;

case "compatHudPaperdoll":
HUDCompat = HUDPortraitCompatMode.valueOf(parser.nextString());
break;

case "healthBlacklist":
ArrayList<String> tempBlacklist = new ArrayList<>();
parser.beginArray();
Expand Down Expand Up @@ -514,4 +520,15 @@ public String toString () {
return "enum.provihealth.seethroughtext." + super.toString().toLowerCase();
}
}

public static enum HUDPortraitCompatMode {
STANDARD,
COMPAT,
NONE;

@Override
public String toString () {
return "enum.provihealth.hudportraitcompatmode." + super.toString().toLowerCase();
}
}
}
97 changes: 59 additions & 38 deletions src/main/java/com/provismet/provihealth/hud/TargetHealthBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.provismet.provihealth.ProviHealthClient;
import com.provismet.provihealth.config.Options;
import com.provismet.provihealth.config.Options.HUDPortraitCompatMode;
import com.provismet.provihealth.config.Options.HUDPosition;
import com.provismet.provihealth.config.Options.HUDType;
import com.provismet.provihealth.util.Visibility;
Expand Down Expand Up @@ -172,45 +173,65 @@ public void onHudRender (DrawContext drawContext, float tickDelta) {
}

// Render Paper Doll
float prevTargetHeadYaw = this.target.getHeadYaw();
float prevPrevTargetHeadYaw = this.target.prevHeadYaw;
float prevTargetBodyYaw = this.target.getBodyYaw();
float prevPrevTargetBodyYaw = this.target.prevBodyYaw;
float prevTargetYaw = this.target.getYaw();

float headBodyYawDifference = this.target.getHeadYaw() - this.target.getBodyYaw();

this.target.setYaw(Options.hudPosition.portraitYAW);
this.target.setBodyYaw(this.target.getYaw());
this.target.prevBodyYaw = this.target.getYaw();
this.target.setHeadYaw(this.target.getYaw() + headBodyYawDifference);
this.target.prevHeadYaw = this.target.getYaw() + headBodyYawDifference;

float renderHeight;
if (this.target.getEyeHeight(EntityPose.STANDING) >= this.target.getHeight() * 0.6) {
renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.5f;
if (renderHeight < 1f) renderHeight = 1f;
if (Options.HUDCompat == HUDPortraitCompatMode.STANDARD) {
float prevTargetHeadYaw = this.target.headYaw;
float prevPrevTargetHeadYaw = this.target.prevHeadYaw;
float prevTargetBodyYaw = this.target.bodyYaw;
float prevPrevTargetBodyYaw = this.target.prevBodyYaw;

this.target.bodyYaw = Options.hudPosition.portraitYAW;
this.target.prevBodyYaw = Options.hudPosition.portraitYAW;
this.target.headYaw = Options.hudPosition.portraitYAW;
this.target.prevHeadYaw = Options.hudPosition.portraitYAW;

float renderHeight;
if (this.target.getEyeHeight(EntityPose.STANDING) >= this.target.getHeight() * 0.6) {
renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.5f;
if (renderHeight < 1f) renderHeight = 1f;
}
else renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.8f;

drawContext.enableScissor(OFFSET_X, OFFSET_Y, OFFSET_X + FRAME_LENGTH, OFFSET_Y + FRAME_LENGTH);
EntityHealthBar.enabled = false;
disabledLabels = true;
this.drawEntity(drawContext, 24 + OFFSET_X, OFFSET_Y, 30,
new Vector3f(0f, renderHeight, 0f),
(new Quaternionf()).rotateZ(3.1415927f),
null,
this.target
);
EntityHealthBar.enabled = true;
disabledLabels = false;
drawContext.disableScissor();

this.target.headYaw = prevTargetHeadYaw;
this.target.prevHeadYaw = prevPrevTargetHeadYaw;
this.target.bodyYaw = prevTargetBodyYaw;
this.target.prevBodyYaw = prevPrevTargetBodyYaw;
}
else if (Options.HUDCompat == HUDPortraitCompatMode.COMPAT) {
float yawOffset = -(Options.hudPosition.portraitYAW - this.target.getBodyYaw()) / MathHelper.DEGREES_PER_RADIAN;

float renderHeight;
if (this.target.getEyeHeight(EntityPose.STANDING) >= this.target.getHeight() * 0.6) {
renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.5f;
if (renderHeight < 1f) renderHeight = 1f;
}
else renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.8f;

drawContext.enableScissor(OFFSET_X, OFFSET_Y, OFFSET_X + FRAME_LENGTH, OFFSET_Y + FRAME_LENGTH);
EntityHealthBar.enabled = false;
disabledLabels = true;
this.drawEntity(drawContext, 24 + OFFSET_X, OFFSET_Y, 30,
new Vector3f(0f, renderHeight, 0f),
(new Quaternionf()).rotateZ(3.1415927f).rotateY(yawOffset),
null,
this.target
);
EntityHealthBar.enabled = true;
disabledLabels = false;
drawContext.disableScissor();
}
else renderHeight = this.target.getEyeHeight(this.target.getPose()) + 0.8f;

drawContext.enableScissor(OFFSET_X, OFFSET_Y, OFFSET_X + FRAME_LENGTH, OFFSET_Y + FRAME_LENGTH);
EntityHealthBar.enabled = false;
disabledLabels = true;
this.drawEntity(drawContext, 24 + OFFSET_X, OFFSET_Y, 30,
new Vector3f(0f, renderHeight, 0f),
(new Quaternionf()).rotateZ(3.1415927f),
null,
this.target
);
EntityHealthBar.enabled = true;
disabledLabels = false;
drawContext.disableScissor();

this.target.setHeadYaw(prevTargetHeadYaw);
this.target.prevHeadYaw = prevPrevTargetHeadYaw;
this.target.setBodyYaw(prevTargetBodyYaw);
this.target.prevBodyYaw = prevPrevTargetBodyYaw;
this.target.setYaw(prevTargetYaw);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/provismet/provihealth/particle/TextParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;

public class TextParticle extends SpriteBillboardParticle {
Expand All @@ -20,6 +21,8 @@ public class TextParticle extends SpriteBillboardParticle {
private final float maxScale;
private final int textColour;

private float prevScale;

@SuppressWarnings("resource")
protected TextParticle (ClientWorld clientWorld, double x, double y, double z, TextParticleEffect particleEffect) {
super(clientWorld, x, y, z);
Expand All @@ -28,6 +31,7 @@ protected TextParticle (ClientWorld clientWorld, double x, double y, double z, T
this.green = particleEffect.getColour().y();
this.blue = particleEffect.getColour().z();
this.scale = 0f;
this.prevScale = 0f;
this.alpha = particleEffect.alpha;
this.textColour = particleEffect.textColour;
this.text = particleEffect.text;
Expand Down Expand Up @@ -75,6 +79,7 @@ protected TextParticle (ClientWorld clientWorld, double x, double y, double z, T
@Override
public void tick () {
super.tick();
this.prevScale = this.scale;

if (this.age > this.maxAge / 2) this.scale -= this.maxScale / (this.maxAge / 2f);
else if (this.scale < this.maxScale) this.scale += this.maxScale / 5f;
Expand Down Expand Up @@ -110,6 +115,11 @@ public int getColour () {
return this.textColour;
}

@Override
public float getSize (float tickDelta) {
return MathHelper.lerp(tickDelta, this.prevScale, this.scale);
}

public Vec3d getPos () {
return new Vec3d(this.x, this.y, this.z);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class EntityHealthBar {
private static final Identifier BARS = ProviHealthClient.identifier("textures/gui/healthbars/in_world.png");
private static final Identifier COMPAT_BARS = ProviHealthClient.identifier("textures/gui/healthbars/in_world_coloured.png");
private static final float TEXTURE_SIZE = 64;
private static final float MOUNT_BAR_PIXEL_LENGTH = 58;

public static boolean enabled = true;

Expand Down Expand Up @@ -163,15 +162,17 @@ private static Text getName (LivingEntity entity) {
}

private static void renderBar (Matrix4f model, VertexConsumer vertexConsumer, int index, float percentage, boolean isMount) {
if (isMount) percentage = MathHelper.lerp(percentage, 3f / TEXTURE_SIZE, 61f / TEXTURE_SIZE);

// All U and V values are a percentage.
final float MIN_U = isMount ? 3f / TEXTURE_SIZE : 0f; // Leftmost pixel
final float MIN_U = 0f; // Leftmost pixel
final float MIN_V = ((index * 12f) / TEXTURE_SIZE) + (isMount ? 7f / TEXTURE_SIZE : 0f); // Topmost pixel
final float MAX_U = percentage * (isMount ? 61f / TEXTURE_SIZE : 1f); // Leftmost pixel
final float MAX_U = percentage; // Rightmost pixel
final float MAX_V = MIN_V + (isMount ? 5f : 7f) / TEXTURE_SIZE; // Bottommost pixel

// X and Y are block coordinates relative to the matrix shenanigans.
final float MIN_X = isMount ? 0.5f * (MOUNT_BAR_PIXEL_LENGTH / TEXTURE_SIZE) : 0.5f; // Pushes the bar half a block to the left, centering it.
final float MAX_X = MIN_X - percentage * (isMount ? MOUNT_BAR_PIXEL_LENGTH / TEXTURE_SIZE : 1f);
final float MIN_X = 0.5f; // Pushes the bar half a block to the left, centering it.
final float MAX_X = MIN_X - percentage;
final float MIN_Y = 0f;
final float MAX_Y = -1f * ((isMount ? 5f : 7f) / TEXTURE_SIZE); // Mount bar is 5 pixels tall, Health bar is 7 pixels tall.

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/provihealth/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"entry.provihealth.worldOffsetY": "Health Bar Offset Y",
"entry.provihealth.damageAlpha": "Damage Particle Alpha",
"entry.provihealth.healingAlpha": "Healing Particle Alpha",
"entry.provihealth.compatHud": "HUD Paperdoll Render Mode",

"enum.provihealth.full": "Full",
"enum.provihealth.portrait_only": "Portrait Only",
Expand All @@ -68,6 +69,10 @@
"enum.provihealth.seethroughtext.none": "Normal Text/Shadows",
"enum.provihealth.seethroughtext.full": "SeeThrough Text/Shadows",

"enum.provihealth.hudportraitcompatmode.standard": "Standard",
"enum.provihealth.hudportraitcompatmode.compat": "Compatibility",
"enum.provihealth.hudportraitcompatmode.none": "None",

"tooltip.provihealth.hudDuration": "How many ticks the HUD display will linger for when not targeting a mob.",
"tooltip.provihealth.targetOverride": "Always render health bar when targeting a mob of this type.",
"tooltip.provihealth.glide": "Determines how quickly the health bar will slide from its old value to new values.\nWarning: Very low values will prevent the health bar visual from catching up with the true value.",
Expand Down

0 comments on commit 86a7e7e

Please sign in to comment.