Skip to content

Commit

Permalink
Arrows are once again rendered for temperature increases/decreases
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 2, 2024
1 parent 77b22c6 commit d2f8102
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import toughasnails.api.TANAPI;
import toughasnails.api.temperature.TemperatureHelper;
import toughasnails.api.temperature.TemperatureLevel;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModConfig;

import java.util.Random;
Expand All @@ -26,6 +27,8 @@ public class TemperatureOverlayRenderer
private static final ResourceLocation HYPERTHERMIA_OUTLINE_LOCATION = new ResourceLocation(TANAPI.MOD_ID, "textures/misc/hyperthermia_outline.png");
private static long updateCounter;
private static long flashCounter;
private static long arrowCounter;
private static ArrowDirection arrowDirection;
private static TemperatureLevel prevTemperatureLevel;

public static void onBeginRenderFood(RenderGuiEvent.Pre event)
Expand Down Expand Up @@ -95,10 +98,17 @@ private static void drawTemperature(GuiGraphics gui, int width, int height, Temp
if (prevTemperatureLevel == null)
prevTemperatureLevel = temperature;

// Reset arrow direction when duration has elapsed
if (updateCounter > arrowCounter)
arrowDirection = null;

// Flash for 16 ticks when the temperature changes
if (prevTemperatureLevel != temperature)
{
flashCounter = updateCounter + 3;
arrowCounter = updateCounter + 15;
if (temperature.compareTo(prevTemperatureLevel) > 0) arrowDirection = ArrowDirection.UP;
else if (temperature.compareTo(prevTemperatureLevel) < 0) arrowDirection = ArrowDirection.DOWN;
}

// Update the prevTemperatureLevel to the current temperature level
Expand All @@ -122,5 +132,34 @@ private static void drawTemperature(GuiGraphics gui, int width, int height, Temp
v += 16;

gui.blit(OVERLAY, left, top, iconIndex, v, 16, 16);

// Draw the arrow
if (arrowDirection != null)
{
gui.blit(OVERLAY, left, top, arrowDirection.getU(15 - (int)(arrowCounter - updateCounter)), arrowDirection.getV(), 16, 16);
}
}

private enum ArrowDirection
{
UP(224),
DOWN(240);

private final int v;

ArrowDirection(int v)
{
this.v = v;
}

public int getU(int frame)
{
return frame * 16;
}

public int getV()
{
return this.v;
}
}
}

0 comments on commit d2f8102

Please sign in to comment.