Created
June 19, 2023 19:45
-
-
Save MasterMank/97db684bf99db1061b7359b202d3e3a2 to your computer and use it in GitHub Desktop.
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
package net.mastermank.corridorsbackrooms.client; | |
import com.mojang.blaze3d.systems.RenderSystem; | |
import com.mojang.blaze3d.vertex.PoseStack; | |
import net.mastermank.corridorsbackrooms.CorridorsBackrooms; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.GuiComponent; | |
import net.minecraft.client.renderer.GameRenderer; | |
import net.minecraft.resources.ResourceLocation; | |
import net.minecraft.util.Mth; | |
import net.minecraft.world.level.Level; | |
import net.minecraftforge.client.gui.overlay.IGuiOverlay; | |
import java.util.Random; | |
public class SanityHUDOverlay { | |
private static final ResourceLocation SANITY_FULL = new ResourceLocation(CorridorsBackrooms.MOD_ID, | |
"textures/sanity/sanity_full.png"); | |
private static final ResourceLocation SANITY_EMPTY = new ResourceLocation(CorridorsBackrooms.MOD_ID, | |
"textures/sanity/sanity_empty.png"); | |
public static final IGuiOverlay SanityHUD = (((gui, poseStack, partialTick, width, height) -> { | |
int x = width / 2; | |
int y = height; | |
RenderSystem.setShader(GameRenderer::getPositionTexShader); | |
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | |
RenderSystem.setShaderTexture(0, SANITY_EMPTY); | |
for (int i = 0; i < 9; i++) { | |
GuiComponent.blit(poseStack, x - -9 + (i * 9), y - 49, 0, 0, 9, 9, | |
9, 9); | |
} | |
RenderSystem.setShaderTexture(0, SANITY_FULL); | |
for (int i = 0; i < 9; i++) { | |
if (ClientSanity.getPlayerSanity() > i) { | |
GuiComponent.blit(poseStack, x - -9 + (i * 9), y - 49, 0, 0, 9, 9, | |
9, 9); | |
} else { | |
break; | |
} | |
} | |
})); | |
public static int tickCount = 0; | |
private static void renderSanity(PoseStack poseStack) { | |
Minecraft minecraft = Minecraft.getInstance(); | |
int playerSanity = ClientSanity.getPlayerSanity(); | |
int screenWidth = minecraft.getWindow().getGuiScaledWidth(); | |
int screenHeight = minecraft.getWindow().getGuiScaledHeight(); | |
if (minecraft.player == null) return; | |
int renderX = (screenWidth / 2 )- 94; | |
int j1 = screenWidth / 2 + 91; | |
int renderY = screenHeight - 54; | |
int sanityRemaining = Mth.ceil(playerSanity); | |
Random random = new Random(); | |
random.setSeed(tickCount * 312871L); | |
int i2 = Mth.ceil((sanityRemaining) / 2.0F / 9.0F); | |
int p_168693_ = Math.max(9 - (i2 - 2), 3); | |
int j = Mth.ceil((double)sanityRemaining); | |
for(int i1 = 0; i1 <= j - 1; ++i1) { | |
int j3 = i1 / 9; | |
int k1 = i1 % 9; | |
int l1 = renderX + k1 * 8; | |
int y = renderY - j3 * p_168693_; | |
if (sanityRemaining <= 4) { | |
if (minecraft.player.level.dimension() == Level.NETHER) { | |
y += random.nextInt(4); | |
} else { | |
y += random.nextInt(2); | |
} | |
} | |
RenderSystem.setShaderTexture(0, SANITY_FULL); | |
GuiComponent.blit(poseStack,renderX + ((i1) * 9),y,0,0,12,12, | |
12,12); | |
} | |
RenderSystem.setShaderTexture(0, SANITY_EMPTY); | |
for(int i1 = ClientSanity.getPlayerSanity(); i1 < 9; i1++) { | |
int j3 = i1 / 9; | |
int k1 = i1 % 9; | |
int l1 = renderX + k1 * 8; | |
int y = renderY - j3 * p_168693_; | |
if (sanityRemaining <= 4) { | |
if (minecraft.player.level.dimension() == Level.NETHER) { | |
y += random.nextInt(4); | |
} else { | |
y += random.nextInt(2); | |
} | |
} | |
RenderSystem.setShaderTexture(0, SANITY_EMPTY); | |
GuiComponent.blit(poseStack,renderX + ((i1) * 9), y,0,0,12,12, | |
12,12); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment