Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xlife.client;
- import com.mojang.blaze3d.systems.RenderSystem;
- import com.xlife.XLife;
- import net.minecraft.Util;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.Gui;
- import net.minecraft.client.gui.GuiGraphics;
- import net.minecraft.resources.ResourceLocation;
- import net.minecraft.world.entity.ai.attributes.Attributes;
- import net.minecraft.world.entity.player.Player;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
- import net.minecraftforge.client.event.RenderGuiOverlayEvent;
- import net.minecraftforge.client.gui.overlay.ForgeGui;
- import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.fml.common.Mod;
- import java.util.HashMap;
- import java.util.Map;
- @Mod.EventBusSubscriber(modid = XLife.modId, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
- public class ClientLifeEvents {
- private static final Map<Integer, ResourceLocation> HEART_COLORS = Util.make(new HashMap<>(), textures -> {
- textures.put(1, new ResourceLocation("textures/gui/icons.png"));
- textures.put(2, XLife.modLoc("textures/gui/hearts/blue.png"));
- textures.put(3, XLife.modLoc("textures/gui/hearts/green.png"));
- textures.put(4, XLife.modLoc("textures/gui/hearts/orange.png"));
- textures.put(5, XLife.modLoc("textures/gui/hearts/pink.png"));
- textures.put(6, XLife.modLoc("textures/gui/hearts/purple.png"));
- textures.put(7, XLife.modLoc("textures/gui/hearts/yellow.png"));
- textures.put(8, XLife.modLoc("textures/gui/hearts/cyan.png"));
- textures.put(9, XLife.modLoc("textures/gui/hearts/lime.png"));
- textures.put(10, XLife.modLoc("textures/gui/hearts/black.png"));
- });
- @SubscribeEvent(receiveCanceled = true)
- public static void handleRenderHearts(RenderGuiOverlayEvent.Pre event) {
- Minecraft mc = Minecraft.getInstance();
- int health = Math.round(mc.player.getMaxHealth());
- if (!mc.gameMode.canHurtPlayer()) return;
- if (event.getOverlay() == VanillaGuiOverlay.PLAYER_HEALTH.type()) {
- event.setCanceled(true);
- mc.getProfiler().push("renderHealth");
- RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
- RenderSystem.setShaderTexture(0, HEART_COLORS.get(health > 20.0F ? 1 : health / 2));
- mc.gui.renderPlayerHealth(event.getGuiGraphics());
- RenderSystem.disableBlend();
- mc.getProfiler().pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement