Skip to content

Commit

Permalink
Add particle alpha setting.
Browse files Browse the repository at this point in the history
This is a pseudo-compatibility fix because Iris breaks the text rendering.
  • Loading branch information
Provismet committed Dec 12, 2023
1 parent 86d4e33 commit 11700c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ public static Screen build (Screen parent) {
.build()
);

particles.addEntry(entryBuilder.startFloatField(Text.translatable("entry.provihealth.damageAlpha"), Options.damageAlpha)
.setDefaultValue(1f)
.setMin(0f)
.setMax(1f)
.setSaveConsumer(newValue -> Options.damageAlpha = newValue)
.build()
);

particles.addEntry(entryBuilder.startColorField(Text.translatable("entry.provihealth.healingColour"), Options.healingColour)
.setDefaultValue(0x00FF00)
.setSaveConsumer(newValue -> {
Expand All @@ -303,6 +311,14 @@ public static Screen build (Screen parent) {
.build()
);

particles.addEntry(entryBuilder.startFloatField(Text.translatable("entry.provihealth.healingAlpha"), Options.healingAlpha)
.setDefaultValue(1f)
.setMin(0f)
.setMax(1f)
.setSaveConsumer(newValue -> Options.healingAlpha = newValue)
.build()
);

particles.addEntry(entryBuilder.startColorField(Text.translatable("entry.provihealth.particleTextColour"), Options.particleTextColour)
.setDefaultValue(0xFFFFFF)
.setSaveConsumer(newValue -> Options.particleTextColour = newValue)
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/provismet/provihealth/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class Options {
public static int particleTextColour = 0xFFFFFF;
public static DamageParticleType particleType = DamageParticleType.RISING;
public static float maxParticleDistance = 16f;
public static float damageAlpha = 1f;
public static float healingAlpha = 1f;

public static SeeThroughText seeThroughTextType = SeeThroughText.STANDARD;
public static boolean compatInWorld = false;
Expand Down Expand Up @@ -167,7 +169,9 @@ public static void save () {
.append("damageParticles", spawnDamageParticles).newLine()
.append("healingParticles", spawnHealingParticles).newLine()
.append("damageColour", damageColour).newLine()
.append("damageAlpha", damageAlpha).newLine()
.append("healingColour", healingColour).newLine()
.append("healingAlpha", healingAlpha).newLine()
.append("particleScale", particleScale).newLine()
.append("particleTextShadow", particleTextShadow).newLine()
.append("particleTextColour", particleTextColour).newLine()
Expand Down Expand Up @@ -341,11 +345,19 @@ public static void load () {
unpackedDamage = Vec3d.unpackRgb(damageColour).toVector3f();
break;

case "damageAlpha":
damageAlpha = (float)parser.nextDouble();
break;

case "healingColour":
healingColour = parser.nextInt();
unpackedHealing = Vec3d.unpackRgb(healingColour).toVector3f();
break;

case "healingAlpha":
healingAlpha = (float)parser.nextDouble();
break;

case "particleScale":
particleScale = (float)parser.nextDouble();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ private void spawnParticles (CallbackInfo info) {
final Entity cameraEntity = MinecraftClient.getInstance().getCameraEntity();
if (cameraEntity != null && (LivingEntity)(Object)this != cameraEntity && this.distanceTo(MinecraftClient.getInstance().getCameraEntity()) <= Options.maxParticleDistance) {
if (this.getHealth() < this.prevHealth && Options.spawnDamageParticles) {
this.getWorld().addParticle(new TextParticleEffect(Options.unpackedDamage, 1f, Options.particleScale, String.format("%d", (int)this.prevHealth - (int)this.getHealth())), this.getX(), this.getEyeY(), this.getZ(), 0f, 0f, 0f);
this.getWorld().addParticle(new TextParticleEffect(Options.unpackedDamage, Options.damageAlpha, Options.particleScale, String.format("%d", (int)this.prevHealth - (int)this.getHealth())), this.getX(), this.getEyeY(), this.getZ(), 0f, 0f, 0f);
}
else if (this.getHealth() > this.prevHealth && Options.spawnHealingParticles) {
this.getWorld().addParticle(new TextParticleEffect(Options.unpackedHealing, 1f, Options.particleScale, String.format("%d", (int)this.getHealth() - (int)this.prevHealth)), this.getX(), this.getEyeY(), this.getZ(), 0f, 0f, 0f);
this.getWorld().addParticle(new TextParticleEffect(Options.unpackedHealing, Options.healingAlpha, Options.particleScale, String.format("%d", (int)this.getHealth() - (int)this.prevHealth)), this.getX(), this.getEyeY(), this.getZ(), 0f, 0f, 0f);
}
}
this.prevHealth = this.getHealth();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/provihealth/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"entry.provihealth.compatText": "In-World Health Bar SeeThrough Text Mode",
"entry.provihealth.compatWorld": "In-World Health Bar Shader Compatibility",
"entry.provihealth.worldOffsetY": "Health Bar Offset Y",
"entry.provihealth.damageAlpha": "Damage Particle Alpha",
"entry.provihealth.healingAlpha": "Healing Particle Alpha",

"enum.provihealth.full": "Full",
"enum.provihealth.portrait_only": "Portrait Only",
Expand Down

0 comments on commit 11700c0

Please sign in to comment.