You are going to learn how to use the methods discussed before to create your own workspace!
Perhatian!
It is highly suggested to go over the "theory" first, and read the "Understanding the library" folder at least once. You are going to use methods explained in there, and things will be taken for granted!
In your event class, inside the onRenderHealth(...) method, use the shouldRenderHealthBar(...) to create your workspace:
@EventBusSubscriber(modid = YouMod.MOD_ID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)public class ModClientEvents {@SubscribeEventpublic static void onRenderHealth(RenderGuiLayerEvent.Pre event) {HealthBar.HEALTH_INSTANCE.shouldRenderHealthBar(event, livingEntity -> {});}}
Perfect, now set up the renderHealthBar(...) method, like this:
HealthBar.HEALTH_INSTANCE.shouldRenderHealthBar(event, livingEntity -> {HealthBar.HEALTH_INSTANCE.renderHealthBar(event);});
In this stage, if you were to run the game the health bar will look exactly as the vanilla version.
Now let's use some manipulation methods to customize the health bar:
HealthBar.HEALTH_INSTANCE.shouldRenderHealthBar(event, livingEntity -> {HealthComponent.setWitheredType(HealthTypes.ModdedTextures.BLUE_HEARTS);HealthComponent.setRegenAnimationSpeed(2);HealthComponent.setRegenAnimationOffSetY(-1);HealthBar.HEALTH_INSTANCE.renderHealthBar(event);});
This way you are changing the look of the withered heart (so if the player has the wither effect, instead of the normal withered heart, the CustomHeartType BLUE_HEARTS will be displayed). Then the animation of the regeneration is slowed down (vanilla is 1 tick per heart, here you are putting 2 ticks per hearts), and the amount the hearts will lift due to the regen effect is reduced (vanilla is -2, you are putting -1, so the heart will lift less). You can now try this setup!
Why don't I put a restriction? Ifs and restrictions
Let's now try to put a restriction to this rendering. For example, this setup should only be applied if the player is underwater! Here is an example:
if (livingEntity.isInWater()) {HealthComponent.setWitheredType(HealthTypes.ModdedTextures.BLUE_HEARTS);HealthComponent.setRegenAnimationSpeed(2);HealthComponent.setRegenAnimationOffSetY(-1);HealthBar.HEALTH_INSTANCE.renderHealthBar(event);}
This way the custom health bar with weird withered hearts and strange regeneration animation will only be rendered when the player is in Water!
Perhatian!
It is suggested to put the renderHealthBar(...) method inside the restrictions you put, this way the health bar will only be overridden and re-rendered only when necessary, without wasting pc resources!
Can I use a CustomHeartType as hearts texture? Custom Heart and Container Type
Obviously it is possible to use custom heart types as well as custom container types, as long as you register correctly (check out the guide on the creation methods). Here is a complete example:
public class MyResources{public static CustomHeartType CUSTOM_HEART = HealthTypes.createCustomHeartType(YourMod.MODID, "customHeart");public static CustomContainerType CUSTOM_CONTAINER = HealthTypes.createCustomHeartType(YourMod.MODID, "customContainer");}
Let's try to override some textures using the complex form of the renderHealthBar(...) method, and the Override Methods:
if (livingEntity.isInWater()) {HealthComponent.setWitheredType(MyResources.CUSTOM_HEART);HealthComponent.setContainerType(MyResources.CUSTOM_CONTAINER);HealthComponent.setRegenAnimationSpeed(2);HealthComponent.setRegenAnimationOffSetY(-1);HealthBar.HEALTH_INSTANCE.renderHealthBar(event, () -> {HealthComponent.overrideHalfHeart(HealthTypes.ModdedTextures.BLUE_HEARTS.half());HealthComponent.overrideContainerBlinking(HealthTypes.ModdedTextures.MAGENTA_HEARTS.fullBlinkingDamage());});}
This way the half red heart will now looks like the blue half heart and the container blinking heart (when taking damage) will looks like magenta blinking heart O_o. This health bar will looks strange but still it is yours, and you can now create your own health bars, looking as weird as you wish!
-> That's it for now! This is what HeartDev has to give, and hopefully this library will make your life a little bit easier when it comes to customizing the health bar! Have fun exploring the mod and stay tuned for newer updates!