-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move heart bar render to thermoo event
- Loading branch information
1 parent
c66779d
commit d2d6ad9
Showing
7 changed files
with
40 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 29 additions & 58 deletions
87
src/main/java/com/github/thedeathlycow/frostiful/client/FrozenHeartsOverlay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
...github/thedeathlycow/frostiful/mixins/compat/colorfulhearts/present/ColdHeartOverlay.java
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
...github/thedeathlycow/frostiful/mixins/compat/overflowingbars/absent/ColdHeartOverlay.java
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
...ithub/thedeathlycow/frostiful/mixins/compat/overflowingbars/present/ColdHeartOverlay.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.