HeartDev

Manipulation Methods

Manipulation methods can be used to set or override textures and behaviour of the health bar. These are stored int the HealthComponent class, can be accessed simply by calling the class (HealthComponent.method(...))

How do I use them? Set methods, and Override methods


These methods can be divided in two big groups: the "Set" methods and the "Override" methods (distinguishable by their name), They operates in different ways, and so they need different application.

Let's suppose you created your workspace and it looks something like this:

HealthBar.HEALTH_INSTANCE.shouldRenderHealthBar(event, livingEntity -> {
HealthBar.HEALTH_INSTANCE.renderHealthBar(event, () -> {
});
});

You can divide your workspace in two parts:

HealthBar.HEALTH_INSTANCE.shouldRenderHealthBar(event, livingEntity -> {
//Manipulation methods
//Set methods
HealthBar.HEALTH_INSTANCE.renderHealthBar(event, () -> {
//Manipulation methods
//Override methods
});
});

As you can see "Set" methods are placed under the shouldRenderHealthBar(...) and, obviously, before the renderHealthBar(...) method. "Override" method, on the other hand, are placed inside the lambda of the renderHealthBar method... But why that?

Set methods

These methods operates by setting the value of certain variables that will then be used in phase 2 of the renderHealthBar(...) methods. They are used before the same method, because they can cast the value of the variables BEFORE they are used, so all resources will build in consequence.

Override methods

These methods instead operates overriding variables that are assigned to a value in between phases and can't therefore be accessed before the renderHealthBar(...). Immagine this method as if it casted an int variable to 12. Event if you used an override method before, to set the variable to 8, it will then be re-assigned to 12. This is why these methods need to be used 'inside' the method, in between phases (generally right before the rendering of the health bar phase), this way that same variable will be still set to 12, but you override its value to 8 right before it is used for rendering!

Methods break down ----

A little break down to better understand the methods.

What does this method do? Set methods


  • setContainerType(...): set a CustomContainerType that will be used instead if the vanilla one.
  • setHeartType(...): set a CustomHeartType that will be used instead if the vanilla normal hearts.
  • setPoisonedType(...): set a CustomHeartType that will be used instead if the vanilla poisoned hearts.
  • setWitheredType(...): set a CustomHeartType that will be used instead if the vanilla withered hearts.
  • setFrozenType(...): set a CustomHeartType that will be used instead if the vanilla frozen hearts.
  • setAbsorbingType(...): set a CustomHeartType that will be used instead if the vanilla absorbing hearts.

  • setRegenAnimationSpeed(...): set for how many ticks a heart should be lifted up when having the regen effect.

Vanilla value: 1 (tick per heart).

  • setRegenAnimationCooldown(...): set for how much time the animation rests between (1 cycle is the animation going from start to tge last heart).

Vanilla value: 15 (ticks).

  • setRegenAnimationOffSetY(...): set how much the heart should be lifted up.

Vanilla value: -2 (pixels. The heart lifts up by 2 pixels).

What does this method do? Override methods


Let's first talk about the methods that overrides the hearts textures. These have a general syntax similar to this:

  • "override" + "Type" + "State" + "Blinking" + "Heart" (...).

This means that in the name of the method you know exactly what you are overriding. For example, using this method:

  • overrideWitheredHalfHeartBlinking(...).

You will override the texture of the withered type of heart, but in his half form, in its blinking form (so the damage blinking).

Instead by using this method:

  • overrideFullHeart(...)

You will override the texture of the normal type of heart (nothing is specified in the Type), in his full form, in his not blinking form (nothing specified)

Now let's see the other methods:

  • overrideStartY(...): set the Y coordinates where the health bar starts rendering.
  • overrideStartX(...): set the X coordinates where the health bar starts rendering.
  • overrideIsHardcore(...): force the rendering of the hardcore variant of the textures, if set tu true.
  • setSpaceBetweenRows(...) (Currently unavailable) : set the space, in pixels, between heart rows.

-> Check out the creation methods guide!