Another week flew by while I tried to tidy up the Health module. So, let’s have a look at what I did this week…

Incoming!

The week began with the Damage events finding themselves in Health module, instead of Core. They were pretty confused at the beginning, but once I updated the HealthAuthoritySystem, they settled down. I also moved the HealthCommands to the new module. The PR which I worked on is:

After some two-three rounds of review with me adding some JavaDoc and tests, and improving the code quality by creating some helper functions, the PR got merged, granting the Health module complete set of heal and damage events.

The next thing was moving over the HUD.

Heads Up!

With the server side (events and system) taken care of, the next part was to add the client system of health.

Presence of health would not be beneficial if the Health Heads Up Display (HUD) is not present in a game. So, I moved the ClientAuthoritySystem, which adds HUD to every player, to the Health module. I also moved the corresponding UI file so that the display is displayed correctly.

However, because of me not examining the UI file, the HUD was not working. It took me half a day (and some help from JellySnake) to make it work. All that was missing was skin asset, which the UI depended upon… The PR on adding the Client System:

Since most of this is just moving the systems from Core to the new module, not many issues were encountered. However, that does not mean that I confronted no issue, which leads us to the last part of the week’s work.

What’s the problem, Block?

The next work was to give “health” to the blocks. So, generally (without the health system, that is), the blocks get destroyed instantly when attacked. However, the health logic introduced the concept of the block first cracking, then getting destroyed. This has two systems and a component to work. Pretty easy to move over, or was it?

After moving the systems and component, and a texture associated with it, I hoped that the blocks should gain some health. However, I was repeatedly getting this error :

java.util.NoSuchElementException: No value present
    at java.util.Optional.get(Optional.java:135)
    at org.terasology.logic.health.BlockDamageRenderer.renderOverlay(Block
DamageRenderer.java:51)

What was causing this, I had no idea. After digging around for some time, I found out I made another mistake. I did not move the BlockDamageEffects.atlas, which is used by block damage renderer to display cracking of blocks.

With that, the block “health” should be working. On trying to test the working of it in-game, I found another issue. The block is not “getting damaged” for some time, and then starts getting damage. This issue has kept me busy for the last two days…

Why block? Why?

After two days of debugging, the issue turns out to be incorrect initialization of HealthComponent in block damage authority system. The currentHealth field of the component was not being assigned explicitly, which resulted in block having arbitrary inital health, most (all?) times greater than maxHealth field. Thus, when it was set equal to the maxHealth field on initialization, the bug vanished…

Working Parallely…

Before I found the block damage issue, I assumed that the extraction is complete and started working on next part of the timeline, which is refactoring some modules to depend on the newly created Health module, so that its working can be verified. Cervator suggested I should start with Potions module, as it has a direct dependence on Health effects.

So after removing health from the core, I added the Health module as a dependency of the core for ease of refactoring. Then I refactored the Potions and AlterationEffects module for depending on the Health module. However, much has to be worked upon them (like thorough in-game testing and adding tests) before these PRs can be merged.

What Next?

With the block damage bug solved, the refactoring work on dependent modules has to be completed. Having some useful tests in the dependent modules will very much helpful when the new logic flow is added.

This is all for now. Stay tuned for more updates…