use of net.minecraft.client.gui.hud.InGameHud in project Potions-HUD-Fabric by Samuel-Martineau.
the class InGameHudMixin method renderStatusEffectOverlay.
/**
* @author Samuel-Martineau
* @reason Prevents the default status effects overlay from being rendered
*/
@Overwrite()
public void renderStatusEffectOverlay(MatrixStack matrices) {
MinecraftClient client = MinecraftClient.getInstance();
InGameHud inGameHud = client.inGameHud;
TextRenderer textRenderer = inGameHud.getTextRenderer();
int spriteSize = 18;
assert client.player != null;
Collection<StatusEffectInstance> statusEffectsCollection = client.player.getStatusEffects();
if (!statusEffectsCollection.isEmpty()) {
RenderSystem.enableBlend();
StatusEffectSpriteManager statusEffectSpriteManager = client.getStatusEffectSpriteManager();
List<Runnable> statusEffectsRunnableList = Lists.newArrayListWithExpectedSize(statusEffectsCollection.size());
RenderSystem.setShaderTexture(0, HandledScreen.BACKGROUND_TEXTURE);
Iterator<StatusEffectInstance> statusEffectsIterator = Ordering.natural().reverse().sortedCopy(statusEffectsCollection).iterator();
int i = 0;
while (statusEffectsIterator.hasNext()) {
int x = PotionsHUDMod.CONFIG_MANAGER.X_OFFSET;
int y = spriteSize * i + PotionsHUDMod.CONFIG_MANAGER.Y_OFFSET;
StatusEffectInstance statusEffectInstance = statusEffectsIterator.next();
StatusEffect statusEffect = statusEffectInstance.getEffectType();
if (statusEffectInstance.shouldShowIcon()) {
Sprite statusEffectSprite = statusEffectSpriteManager.getSprite(statusEffect);
statusEffectsRunnableList.add(() -> {
RenderSystem.setShaderTexture(0, statusEffectSprite.getAtlas().getId());
DrawableHelper.drawSprite(matrices, x, y, inGameHud.getZOffset(), spriteSize, spriteSize, statusEffectSprite);
int duration = statusEffectInstance.getDuration() / 20;
long mins = TimeUnit.SECONDS.toMinutes(duration);
long secs = duration - TimeUnit.MINUTES.toSeconds(mins);
String formattedDuration;
if (statusEffectInstance.isPermanent())
formattedDuration = "∞";
else if (mins == 0)
formattedDuration = secs + " sec";
else
formattedDuration = String.format("%d min, %d sec", mins, secs);
float textX = x + spriteSize + 3;
float textY = y + (spriteSize / 2f - textRenderer.fontHeight / 2.5f);
int color;
if (duration <= 5)
color = 0xFF5555;
else if (duration <= 15)
color = 0xFFAA00;
else if (duration <= 25)
color = 0xFFFF55;
else
color = 0xFFFFFF;
textRenderer.draw(matrices, formattedDuration, textX, textY, color);
});
}
i++;
}
statusEffectsRunnableList.forEach(Runnable::run);
}
}
use of net.minecraft.client.gui.hud.InGameHud in project Potions-HUD-Fabric by Samuel-Martineau.
the class HUD method render.
private void render() {
final PlayerEntity player = client.player;
final InGameHud inGameHud = client.inGameHud;
final TextRenderer textRenderer = client.textRenderer;
final MatrixStack matrixStack = new MatrixStack();
if (player == null)
return;
Collection<StatusEffectInstance> statusEffects = player.getStatusEffects();
final GameOptions gameOptions = ((MinecraftClientMixin) MinecraftClient.getInstance()).getGameOptions();
if (!statusEffects.isEmpty() && !gameOptions.debugEnabled) {
RenderSystem.enableBlend();
StatusEffectSpriteManager statusEffectSpriteManager = client.getStatusEffectSpriteManager();
List<Runnable> statusEffectsRunnables = Lists.newArrayListWithExpectedSize(statusEffects.size());
final int spriteSize = 18;
for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(statusEffects)) {
StatusEffect statusEffect = statusEffectInstance.getEffectType();
final int duration = statusEffectInstance.getDuration() / 20;
final long mins = TimeUnit.SECONDS.toMinutes(duration);
final long secs = duration - TimeUnit.MINUTES.toSeconds(mins);
String formattedDuration;
if (statusEffectInstance.isPermanent())
formattedDuration = "∞";
else if (mins == 0)
formattedDuration = secs + " sec";
else
formattedDuration = String.format("%d min, %d sec", mins, secs);
final int x = 3;
final int y = spriteSize * statusEffectsRunnables.size() + 3;
System.out.println("\n \n---\n ");
Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
System.out.println(sprite);
System.out.println(sprite.getAtlas().getId());
System.out.println(x);
System.out.println(y);
System.out.println(inGameHud.getZOffset());
statusEffectsRunnables.add(() -> {
client.getTextureManager().bindTexture(sprite.getAtlas().getId());
DrawableHelper.drawSprite(matrixStack, x, y, inGameHud.getZOffset(), 18, 18, sprite);
final float textYOffset = spriteSize / 2f - textRenderer.fontHeight / 2.5f;
int color;
if (duration <= 5)
color = 0xFF5555;
else if (duration <= 15)
color = 0xFFAA00;
else if (duration <= 25)
color = 0xFFFF55;
else
color = 0xFFFFFF;
textRenderer.draw(matrixStack, formattedDuration, x + spriteSize + 3, y + textYOffset, color);
});
}
statusEffectsRunnables.forEach(Runnable::run);
}
}
Aggregations