Skip to content

Commit

Permalink
fire hearts in testmod
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow committed Mar 25, 2024
1 parent d1b4117 commit 34b4440
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public interface RenderHealthBarCallback {
* @param heartPositions An array of heart positions on the HUD. Elements may be null, indicating that a heart
* should not be rendered at this index.
* @param displayHealth How many half hearts are to be displayed
* @param maxDisplayHeath The maximum number of half hearts to be displayed
* @param maxDisplayHealth The maximum number of half hearts to be displayed
*/
void render(
DrawContext context,
PlayerEntity player,
Vector2i[] heartPositions,
int displayHealth,
int maxDisplayHeath
int maxDisplayHealth
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import java.util.Optional;

/**
* Mod-agnostic Seasons enum for any Thermoo dependencies.
* Mod-agnostic Seasons enum. Thermoo does not provide seasons itself, but this can be used to better integrate with any
* mods that do provide seasons.
*/
public enum ThermooSeasons {
SPRING,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.github.thedeathlycow.thermoo.testmod;

import com.github.thedeathlycow.thermoo.api.client.HeartOverlayRenderEvent;
import com.github.thedeathlycow.thermoo.impl.Thermoo;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector2i;

public class ThermooTestModClient implements ClientModInitializer {

public static final Identifier HEART_OVERLAY_TEXTURE = Thermoo.id("textures/gui/fire_heart_overlay.png");

private static final int TEXTURE_WIDTH = 18;
private static final int TEXTURE_HEIGHT = 30;

@Override
public void onInitializeClient() {
HeartOverlayRenderEvent.AFTER_HEALTH_BAR.register(ThermooTestModClient::renderFireHeartBar);
}

public static void renderFireHeartBar(
DrawContext context,
PlayerEntity player,
Vector2i[] heartPositions,
int displayHealth,
int maxDisplayHealth
) {
int fireHeartPoints = getNumFirePoints(player, maxDisplayHealth);
int fireHearts = getNumFireHeartsFromPoints(fireHeartPoints, maxDisplayHealth);

for (int m = 0; m < fireHearts; m++) {
// is half heart if this is the last heart being rendered and we have an odd
// number of frozen health points
int x = heartPositions[m].x;
int y = heartPositions[m].y - 1;
boolean isHalfHeart = m + 1 >= fireHearts && (fireHeartPoints & 1) == 1; // is odd check

int u = isHalfHeart ? 9 : 0;

context.drawTexture(HEART_OVERLAY_TEXTURE, x, y, u, 0, 9, 10, TEXTURE_WIDTH, TEXTURE_HEIGHT);
}
}

private static int getNumFirePoints(@NotNull PlayerEntity player, int maxDisplayHealth) {
float tempScale = player.thermoo$getTemperatureScale();
if (tempScale <= 0f) {
return 0;
}
return (int) (tempScale * maxDisplayHealth);
}

private static int getNumFireHeartsFromPoints(int fireHealthPoints, int maxDisplayHealth) {
// number of whole hearts
int frozenHealthHearts = MathHelper.ceil(fireHealthPoints / 2.0f);

return Math.min(maxDisplayHealth / 2, frozenHealthHearts);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"main": [
"com.github.thedeathlycow.thermoo.testmod.ThermooTestMod"
],
"client": [
"com.github.thedeathlycow.thermoo.testmod.ThermooTestModClient"
],
"fabric-gametest": [
]
}
Expand Down

0 comments on commit 34b4440

Please sign in to comment.