Skip to content

Commit

Permalink
move heart bar render to thermoo event
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow committed Mar 27, 2024
1 parent c66779d commit d2d6ad9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 296 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.github.thedeathlycow.frostiful;

import com.github.thedeathlycow.frostiful.block.FCutouts;
import com.github.thedeathlycow.frostiful.client.FrozenHeartsOverlay;
import com.github.thedeathlycow.frostiful.client.model.FEntityModelLayers;
import com.github.thedeathlycow.frostiful.client.render.FrostWandItemRenderer;
import com.github.thedeathlycow.frostiful.client.render.entity.FEntityRenderers;
import com.github.thedeathlycow.frostiful.particle.client.FParticleFactoryRegistry;
import com.github.thedeathlycow.frostiful.registry.FItems;
import com.github.thedeathlycow.frostiful.server.network.PointWindSpawnPacket;
import com.github.thedeathlycow.frostiful.server.network.PointWindSpawnPacketListener;
import com.github.thedeathlycow.thermoo.api.client.StatusBarOverlayRenderEvents;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
Expand Down Expand Up @@ -42,10 +43,8 @@ public void onInitializeClient() {

FCutouts.registerCutouts();
FParticleFactoryRegistry.registerFactories();
ClientPlayNetworking.registerGlobalReceiver(
PointWindSpawnPacket.ID,
PointWindSpawnPacketListener::receive
);
ClientPlayNetworking.registerGlobalReceiver(PointWindSpawnPacket.ID, PointWindSpawnPacketListener::receive);
StatusBarOverlayRenderEvents.AFTER_HEALTH_BAR.register(FrozenHeartsOverlay::afterHealthBar);


Frostiful.LOGGER.info("Initialized Frostiful client!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,57 @@
package com.github.thedeathlycow.frostiful.client;

import com.github.thedeathlycow.frostiful.Frostiful;
import com.github.thedeathlycow.frostiful.compat.FrostifulIntegrations;
import com.github.thedeathlycow.frostiful.config.FrostifulConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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;

@Environment(EnvType.CLIENT)
public class FrozenHeartsOverlay {

public static final FrozenHeartsOverlay INSTANCE = new FrozenHeartsOverlay();
public static final Identifier HEART_OVERLAY_TEXTURE = Frostiful.id("textures/gui/cold_heart_overlay.png");

public static final Identifier HEART_OVERLAY_TEXTURE = new Identifier(Frostiful.MODID, "textures/gui/cold_heart_overlay.png");
public static final int MAX_COLD_HEARTS = 20;

private final int[] heartXPositions = new int[MAX_COLD_HEARTS];
private final int[] heartYPositions = new int[MAX_COLD_HEARTS];

public void setHeartPos(int index, int xPos, int yPos) {
if (index >= 0 && index < MAX_COLD_HEARTS) {
this.heartXPositions[index] = xPos;
this.heartYPositions[index] = yPos;
}
}

public int getNumColdPoints(@NotNull PlayerEntity player) {
float freezingProgress = player.thermoo$getTemperatureScale();
if (freezingProgress >= 0f) {
return 0;
}
freezingProgress = -freezingProgress;

final float playerMaxHealth = player.getMaxHealth();

// number of half cold hearts
int frozenHealthPoints;
// match the number of cold hearts to the display if hearts render is altered
if (FrostifulIntegrations.isHeartsRenderOverridden()) {
// 20 is the (expected) maximum number of health points that the render mod will display
frozenHealthPoints = (int) (freezingProgress * Math.min(MAX_COLD_HEARTS, playerMaxHealth));
} else {
// max cold hearts is multiplied by 2 to covert to points
frozenHealthPoints = (int) (freezingProgress * Math.min(MAX_COLD_HEARTS * 2.0f, playerMaxHealth));
}
return frozenHealthPoints;
}

public int getNumColdHeartsFromPoints(int frozenHealthPoints) {
// number of whole hearts
int frozenHealthHearts = MathHelper.ceil(frozenHealthPoints / 2.0f);

return Math.min(MAX_COLD_HEARTS, frozenHealthHearts);
}

public void drawHeartOverlayBar(
public static void afterHealthBar(
DrawContext context,
PlayerEntity player
PlayerEntity player,
Vector2i[] heartPositions,
int displayHealth,
int maxDisplayHealth
) {

FrostifulConfig config = Frostiful.getConfig();
if (!config.clientConfig.doColdHeartOverlay()) {
if (!config.clientConfig.doColdHeartOverlay() || player.thermoo$isWarm()) {
return;
}
int frozenHealthPoints = getNumColdPoints(player);

int frozenHealthPoints = getNumColdPoints(player, maxDisplayHealth);
int frozenHealthHearts = getNumColdHeartsFromPoints(frozenHealthPoints);
for (int m = 0; m < frozenHealthHearts; m++) {
for (int i = 0; i < frozenHealthHearts; i++) {
Vector2i pos = heartPositions[i];
if (pos == null) {
continue;
}
// is half heart if this is the last heart being rendered and we have an odd
// number of frozen health points
int x = heartXPositions[m];
int y = heartYPositions[m];
boolean isHalfHeart = m + 1 >= frozenHealthHearts && (frozenHealthPoints & 1) == 1; // is odd check
boolean isHalfHeart = i + 1 >= frozenHealthHearts && (frozenHealthPoints & 1) == 1; // is odd check

int u = isHalfHeart ? 9 : 0;
context.drawTexture(HEART_OVERLAY_TEXTURE, x, y, u, 0, 9, 10, 18, 10);
context.drawTexture(HEART_OVERLAY_TEXTURE, pos.x, pos.y, u, 0, 9, 10, 18, 10);
}
}

private static int getNumColdPoints(@NotNull PlayerEntity player, int maxDisplayHealth) {
float freezingProgress = -player.thermoo$getTemperatureScale();
return (int)(freezingProgress * maxDisplayHealth);
}

private static int getNumColdHeartsFromPoints(int frozenHealthPoints) {
// number of whole hearts
return MathHelper.ceil(frozenHealthPoints / 2.0f);
}

private FrozenHeartsOverlay() {

}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d2d6ad9

Please sign in to comment.