Skip to content

Commit

Permalink
Add settings to control text shadow and see-through.
Browse files Browse the repository at this point in the history
* Add settings to control text shadow and see-through.
  • Loading branch information
Provismet authored Dec 11, 2023
1 parent c411fb8 commit c72cc2a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static Screen build (Screen parent) {
ConfigCategory hud = builder.getOrCreateCategory(Text.translatable("category.provihealth.hud"));
ConfigCategory health = builder.getOrCreateCategory(Text.translatable("category.provihealth.health"));
ConfigCategory particles = builder.getOrCreateCategory(Text.translatable("category.provihealth.particles"));
ConfigCategory compatibility = builder.getOrCreateCategory(Text.translatable("category.provihealth.compat"));

hud.addEntry(entryBuilder.startIntField(Text.translatable("entry.provihealth.hudDuration"), Options.maxHealthBarTicks)
.setDefaultValue(40)
Expand Down Expand Up @@ -150,6 +151,12 @@ public static Screen build (Screen parent) {
.build()
);

health.addEntry(entryBuilder.startBooleanToggle(Text.translatable("entry.provihealth.worldShadows"), Options.worldShadows)
.setDefaultValue(true)
.setSaveConsumer(newValue -> Options.worldShadows = newValue)
.build()
);

health.addEntry(entryBuilder.startFloatField(Text.translatable("entry.provihealth.maxDistance"), Options.maxRenderDistance)
.setMin(0f)
.setDefaultValue(24f)
Expand Down Expand Up @@ -315,6 +322,13 @@ public static Screen build (Screen parent) {
.build()
);

compatibility.addEntry(entryBuilder.startBooleanToggle(Text.translatable("entry.provihealth.compatText"), Options.noSeeThroughText)
.setDefaultValue(false)
.setTooltip(Text.translatable("tooltip.provihealth.compatText"))
.setSaveConsumer(newValue -> Options.noSeeThroughText = newValue)
.build()
);

builder.setSavingRunnable(Options::save);
return builder.build();
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/provismet/provihealth/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class Options {
public static Vector3f unpackedEndWorld = Vec3d.unpackRgb(worldEndColour).toVector3f();
public static boolean worldGradient = false;
public static boolean overrideLabels = false;
public static boolean worldShadows = true;

public static boolean spawnDamageParticles = true;
public static boolean spawnHealingParticles = false;
Expand All @@ -81,6 +82,8 @@ public class Options {
public static DamageParticleType particleType = DamageParticleType.RISING;
public static float maxParticleDistance = 16f;

public static boolean noSeeThroughText = false;

@SuppressWarnings("resource")
public static boolean shouldRenderHealthFor (LivingEntity livingEntity) {
if (blacklist.contains(EntityType.getId(livingEntity.getType()).toString())) return false;
Expand Down Expand Up @@ -139,6 +142,7 @@ public static void save () {
.append("replaceLabels", overrideLabels).newLine()
.append("worldGlide", worldGlide).newLine()
.append("worldHealthText", showTextInWorld).newLine()
.append("worldTextShadows", worldShadows).newLine()
.append("maxRenderDistance", maxRenderDistance).newLine()
.append("barScale", worldHealthBarScale).newLine()
.append("worldGradient", worldGradient).newLine()
Expand All @@ -165,6 +169,7 @@ public static void save () {
.append("particleTextColour", particleTextColour).newLine()
.append("particleType", particleType.name()).newLine()
.append("maxParticleDistance", maxParticleDistance).newLine()
.append("topLayerText", noSeeThroughText).newLine()
.createArray("healthBlacklist", blacklist).newLine()
.createArray("hudBlacklist", blacklistHUD).newLine(false)
.closeObject()
Expand Down Expand Up @@ -239,6 +244,10 @@ public static void load () {
case "worldHealthText":
showTextInWorld = parser.nextBoolean();
break;

case "worldTextShadows":
worldShadows = parser.nextBoolean();
break;

case "maxRenderDistance":
maxRenderDistance = (float)parser.nextDouble();
Expand Down Expand Up @@ -348,6 +357,10 @@ public static void load () {
maxParticleDistance = (float)parser.nextDouble();
break;

case "topLayerText":
noSeeThroughText = parser.nextBoolean();
break;

case "healthBlacklist":
ArrayList<String> tempBlacklist = new ArrayList<>();
parser.beginArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,23 @@ public static void render (Entity entity, float tickDelta, MatrixStack matrices,
nameY -= 9;
}

if (target.shouldRenderName() && !target.isSneaky()) {
textRenderer.draw(targetName, nameX + 1, nameY + 1, 0x404040, false, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
textRenderer.draw(healthString, healthX + 1, healthY + 1, 0x404040, false, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
if (target.shouldRenderName() && !target.isSneaky() && !Options.noSeeThroughText) {
if (Options.worldShadows) {
textRenderer.draw(targetName, nameX + 1, nameY + 1, 0x404040, false, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
textRenderer.draw(healthString, healthX + 1, healthY + 1, 0x404040, false, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
}

matrices.translate(0, 0, 0.03f);
textModel = matrices.peek().getPositionMatrix();
textRenderer.draw(targetName, nameX, nameY, 0xFFFFFF, false, textModel, vertexConsumers, TextLayerType.SEE_THROUGH, 0, light);
textRenderer.draw(healthString, healthX, healthY, 0xFFFFFF, false, textModel, vertexConsumers, TextLayerType.SEE_THROUGH, 0, light);
}
else {
textRenderer.draw(targetName, nameX, nameY, 0xFFFFFF, true, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
textRenderer.draw(healthString, healthX, healthY, 0xFFFFFF, true, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
textRenderer.draw(targetName, nameX, nameY, 0xFFFFFF, Options.worldShadows, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
textRenderer.draw(healthString, healthX, healthY, 0xFFFFFF, Options.worldShadows, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
}
}
else textRenderer.draw(healthString, -(textRenderer.getWidth(healthString)) / 2f, -10, 0xFFFFFF, true, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
else textRenderer.draw(healthString, -(textRenderer.getWidth(healthString)) / 2f, -10, 0xFFFFFF, Options.worldShadows, textModel, vertexConsumers, TextLayerType.NORMAL, 0, light);
matrices.pop();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/provihealth/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"category.provihealth.hud": "HUD",
"category.provihealth.health": "In-World",
"category.provihealth.particles": "Particles",
"category.provihealth.compat": "Compatibility",

"subcategory.provihealth.boss": "Bosses",
"subcategory.provihealth.hostile": "Hostile Mobs",
Expand Down Expand Up @@ -40,6 +41,8 @@
"entry.provihealth.barStartColour": "Full Health Colour",
"entry.provihealth.barEndColour": "Low Health Colour",
"entry.provihealth.overrideLabels": "Replace Nameplates",
"entry.provihealth.worldShadows": "Text Shadow",
"entry.provihealth.compatText": "Disable Top-Layer Text",

"enum.provihealth.full": "Full",
"enum.provihealth.portrait_only": "Portrait Only",
Expand All @@ -64,6 +67,7 @@
"tooltip.provihealth.hudOffsetY": "As a percentage of the window height.",
"tooltip.provihealth.gradient": "Whether or not the health bar will change color as it gets lower.\nTurning this off sets the bar color to the starting value.",
"tooltip.provihealth.overrideLabels": "When true health bar text will include the name of the mob and nameplates will not be rendered.\nWhen false health bar text will only show the health values, and the bar will move upwards when a nameplate is being rendered.\nWarning: Only the name of the mob is added to the health bar, if a mod/plugin/scoreboard adds additional lines of text to the nameplate then that text will be lost.",
"tooltip.provihealth.compatText": "Prevents in-world health bar text from rendering through walls for mobs that have top-layer nameplates (such as Players).\nThis is a compatibility setting and should only be used if another mod is causing text for those mobs to render incorrectly.",

"entity.provihealth.unknownPlayer": "[Invisible Player]"
}

0 comments on commit c72cc2a

Please sign in to comment.