Skip to content

Commit

Permalink
Shader compat (#10)
Browse files Browse the repository at this point in the history
* Add more compatibility settings.

* Add null registries and item stack registering.

Mods can now set portrait or icons to null (applying default settings). ItemStacks allow for custom NBT to be used for the visuals, such as enchantments.

* Add particle alpha setting.
  • Loading branch information
Provismet authored Dec 12, 2023
1 parent c72cc2a commit 405dacc
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 60 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.2+build.1
loader_version=0.14.22

# Mod Properties
mod_version=1.2.0+1.20.2
mod_version=1.2.1+1.20.2
maven_group=com.provismet
archives_base_name=provihealth

Expand Down
107 changes: 94 additions & 13 deletions src/main/java/com/provismet/provihealth/api/ProviHealthApi.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.provismet.provihealth.api;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.provismet.provihealth.hud.BorderRegistry;

import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

public interface ProviHealthApi {
Expand All @@ -20,7 +24,7 @@ public interface ProviHealthApi {
* @param item The item to serve as the icon.
* @return Whether or not the registry succeeded. This is false if the entity group already has an icon.
*/
public default boolean registerIcon (EntityGroup entityGroup, Item item) {
public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item) {
return this.registerIcon(entityGroup, item, false);
}

Expand All @@ -34,7 +38,7 @@ public default boolean registerIcon (EntityGroup entityGroup, Item item) {
* @param item The item to serve as the icon.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerIcon (EntityGroup entityGroup, Item item, boolean force) {
public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item, boolean force) {
return BorderRegistry.registerItem(entityGroup, item.getDefaultStack(), force);
}

Expand All @@ -48,7 +52,7 @@ public default boolean registerIcon (EntityGroup entityGroup, Item item, boolean
* @param item The item that will act as the icon for this entity type.
* @return Whether or not the registry succeeded. This is false if the entity type already has an icon.
*/
public default boolean registerIcon (EntityType<?> type, Item item) {
public default boolean registerIcon (EntityType<?> type, @NotNull Item item) {
return this.registerIcon(type, item, false);
}

Expand All @@ -63,69 +67,146 @@ public default boolean registerIcon (EntityType<?> type, Item item) {
* @param force Whether or not this registration should override any pre-existing icon for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerIcon (EntityType<?> type, Item item, boolean force) {
public default boolean registerIcon (EntityType<?> type, @NotNull Item item, boolean force) {
return BorderRegistry.registerItem(type, item.getDefaultStack(), force);
}


/**
* Sets an icon to appear on the HUD for a certain entity type. This method accepts ItemStacks with NBT.
* If available, icons for entity types will suppress icons for entity groups.
*
* Setting item = null means no item will be rendered. This is still considered a valid registry.
*
* Only one icon can be registered per entity type. This registry may suppress or be suppressed by other mods.
*
* @param type The entity type.
* @param item The item stack that will act as the icon for this entity type.
* @return Whether or not the registry succeeded. This is false if the entity type already has an icon.
*/
public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStack item) {
return this.registerIconStack(type, item, false);
}

/**
* Sets an icon to appear on the HUD for a certain entity type. This method accepts ItemStacks with NBT.
* If available, icons for entity types will suppress icons for entity groups.
*
* Setting item = null means no item will be rendered. This is still considered a valid registry.
*
* Only one icon can be registered per entity type. This registry may suppress or be suppressed by other mods.
*
* @param type The entity type.
* @param item The item stack that will act as the icon for this entity type.
* @param force Whether or not this registration should override any pre-existing icon for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStack item, boolean force) {
return BorderRegistry.registerItem(type, item, force);
}

/**
* Registers an icon that will display on top of the health bar in the HUD for a specific entity group.
* This method accepts an ItemStack with NBT. Only one icon may be registered per entity group.
*
* Setting item = null means no item will be rendered. This is still considered a valid registry.
*
* Only one icon can be registered per entity group. This registry may suppress or be suppressed by other mods.
*
* @param type The entity group.
* @param item The item stack that will act as the icon for this entity group.
* @return Whether or not the registry succeeded. This is false if the entity group already has an icon.
*/
public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack item) {
return this.registerIconStack(type, item, false);
}

/**
* Registers an icon that will display on top of the health bar in the HUD for a specific entity group.
* This method accepts an ItemStack with NBT. Only one icon may be registered per entity group.
*
* Setting item = null means no item will be rendered. This is still considered a valid registry.
*
* Only one icon can be registered per entity group. This registry may suppress or be suppressed by other mods.
*
* @param type The entity group.
* @param item The item stack that will act as the icon for this entity group.
* @param force Whether or not this registration should override any pre-existing icon for the same entity group.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack item, boolean force) {
return BorderRegistry.registerItem(type, item, force);
}

/**
* Registers a portrait for an entity group. This will affect the HUD health bar.
* Only one portrait may be registered per entity group.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* Setting resource = null means that the default portrait will be rendered.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* The image for the frame must be 96x48 in size. With the foreground (48x48) on the left and the background (48x48) on the right.
*
* @param entityGroup The entity group.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @return Whether or not the registry succeeded. This is false if the entity group already has a portrait.
*/
public default boolean registerPortrait (EntityGroup entityGroup, Identifier resource) {
public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Identifier resource) {
return this.registerPortrait(entityGroup, resource, false);
}

/**
* Registers a portrait for an entity group. This will affect the HUD health bar.
* Only one portrait may be registered per entity group.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* Setting resource = null means that the default portrait will be rendered.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* The image for the frame must be 96x48 in size. With the foreground (48x48) on the left and the background (48x48) on the right.
*
* @param entityGroup The entity group.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @param force Whether or not this registration should override any pre-existing portrait for the same entity group.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerPortrait (EntityGroup entityGroup, Identifier resource, boolean force) {
public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Identifier resource, boolean force) {
return BorderRegistry.registerBorder(entityGroup, resource, force);
}

/**
* Sets the HUD portrait frame (imagery around the paper doll) for a certain entity type.
* If available, a portrait for an entity type will suppress the portrait for an entity group.
*
* Only one portrait can be registered per entity type. This registry may suppress or be suppressed by other mods.
*
* Setting resource = null means that the default portrait will be rendered.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* The image for the frame must be 96x48 in size. With the foreground (48x48) on the left and the background (48x48) on the right.
*
* @param type The entity type.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @param force Whether or not this registration should override any pre-existing portrait for the same entity type.
* @return Whether or not the registry succeeded. This is false if the entity type already has a portrait.
*/
public default boolean registerPortrait (EntityType<?> type, Identifier resource) {
public default boolean registerPortrait (EntityType<?> type, @Nullable Identifier resource) {
return this.registerPortrait(type, resource, false);
}

/**
* Sets the HUD portrait frame (imagery around the paper doll) for a certain entity type.
* If available, a portrait for an entity type will suppress the portrait for an entity group.
*
* Only one portrait can be registered per entity type. This registry may suppress or be suppressed by other mods.
*
* Setting resource = null means that the default portrait will be rendered.
*
* If your mod introduces new entity groups, use this method to define a portrait for them.
* The image for the frame must be 96x48 in size. With the foreground (48x48) on the left and the background (48x48) on the right.
*
* @param type The entity type.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @param force Whether or not this registration should override any pre-existing portrait for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
*/
public default boolean registerPortrait (EntityType<?> type, Identifier resource, boolean force) {
public default boolean registerPortrait (EntityType<?> type, @Nullable Identifier resource, boolean force) {
return BorderRegistry.registerBorder(type, resource, force);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.provismet.provihealth.config.Options.DamageParticleType;
import com.provismet.provihealth.config.Options.HUDPosition;
import com.provismet.provihealth.config.Options.HUDType;
import com.provismet.provihealth.config.Options.SeeThroughText;
import com.provismet.provihealth.config.Options.VisibilityType;

import me.shedaniel.clothconfig2.api.ConfigBuilder;
Expand Down Expand Up @@ -173,6 +174,12 @@ public static Screen build (Screen parent) {
.build()
);

health.addEntry(entryBuilder.startFloatField(Text.translatable("entry.provihealth.worldOffsetY"), Options.worldOffsetY)
.setDefaultValue(0f)
.setSaveConsumer(newValue -> Options.worldOffsetY = newValue)
.build()
);

health.addEntry(entryBuilder.startBooleanToggle(Text.translatable("entry.provihealth.gradient"), Options.worldGradient)
.setDefaultValue(false)
.setTooltip(Text.translatable("tooltip.provihealth.gradient"))
Expand Down Expand Up @@ -287,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 @@ -296,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 All @@ -322,10 +345,17 @@ public static Screen build (Screen parent) {
.build()
);

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

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

Expand Down
45 changes: 41 additions & 4 deletions src/main/java/com/provismet/provihealth/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class Options {
public static boolean worldGradient = false;
public static boolean overrideLabels = false;
public static boolean worldShadows = true;
public static float worldOffsetY = 0f;

public static boolean spawnDamageParticles = true;
public static boolean spawnHealingParticles = false;
Expand All @@ -81,8 +82,12 @@ 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 boolean noSeeThroughText = false;
public static SeeThroughText seeThroughTextType = SeeThroughText.STANDARD;
public static boolean compatInWorld = false;
public static boolean compatInHUD = false;

@SuppressWarnings("resource")
public static boolean shouldRenderHealthFor (LivingEntity livingEntity) {
Expand Down Expand Up @@ -145,6 +150,7 @@ public static void save () {
.append("worldTextShadows", worldShadows).newLine()
.append("maxRenderDistance", maxRenderDistance).newLine()
.append("barScale", worldHealthBarScale).newLine()
.append("worldOffsetY", worldOffsetY).newLine()
.append("worldGradient", worldGradient).newLine()
.append("worldStartColour", worldStartColour).newLine()
.append("worldEndColour", worldEndColour).newLine()
Expand All @@ -163,13 +169,16 @@ 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()
.append("particleType", particleType.name()).newLine()
.append("maxParticleDistance", maxParticleDistance).newLine()
.append("topLayerText", noSeeThroughText).newLine()
.append("topLayerTextType", seeThroughTextType.name()).newLine()
.append("compatWorldBar", compatInWorld).newLine()
.createArray("healthBlacklist", blacklist).newLine()
.createArray("hudBlacklist", blacklistHUD).newLine(false)
.closeObject()
Expand Down Expand Up @@ -257,6 +266,10 @@ public static void load () {
worldHealthBarScale = (float)parser.nextDouble();
break;

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

case "worldGradient":
worldGradient = parser.nextBoolean();
break;
Expand Down Expand Up @@ -332,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 All @@ -357,8 +378,12 @@ public static void load () {
maxParticleDistance = (float)parser.nextDouble();
break;

case "topLayerText":
noSeeThroughText = parser.nextBoolean();
case "topLayerTextType":
seeThroughTextType = SeeThroughText.valueOf(parser.nextString());
break;

case "compatWorldBar":
compatInWorld = parser.nextBoolean();
break;

case "healthBlacklist":
Expand All @@ -383,6 +408,7 @@ public static void load () {

default:
ProviHealthClient.LOGGER.warn("Unknown label \"" + label + "\" found in config.");
parser.skipValue();
break;
}
}
Expand Down Expand Up @@ -471,4 +497,15 @@ public String toString () {
return "enum.provihealth." + super.toString().toLowerCase();
}
}

public static enum SeeThroughText {
STANDARD,
NONE,
FULL;

@Override
public String toString () {
return "enum.provihealth.seethroughtext." + super.toString().toLowerCase();
}
}
}
Loading

0 comments on commit 405dacc

Please sign in to comment.