mirror of
https://github.com/kami-blue/client
synced 2025-02-20 23:27:14 +00:00
finished hungeroverlay (closes #572)
This commit is contained in:
parent
dbeff72cf5
commit
aa56c7745b
@ -8,7 +8,10 @@ import me.zeroeightsix.kami.gui.UIRenderer;
|
||||
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
||||
import me.zeroeightsix.kami.gui.rgui.component.container.use.Frame;
|
||||
import me.zeroeightsix.kami.module.modules.client.CommandConfig;
|
||||
import me.zeroeightsix.kami.module.modules.misc.HungerOverlay;
|
||||
import me.zeroeightsix.kami.module.modules.render.BossStack;
|
||||
import me.zeroeightsix.kami.util.HungerOverlayRenderHelper;
|
||||
import me.zeroeightsix.kami.util.HungerOverlayUtils;
|
||||
import me.zeroeightsix.kami.util.KamiTessellator;
|
||||
import me.zeroeightsix.kami.util.Wrapper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -16,7 +19,11 @@ import net.minecraft.client.gui.GuiChat;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.gui.inventory.GuiShulkerBox;
|
||||
import net.minecraft.entity.passive.AbstractHorse;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.FoodStats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.GuiIngameForge;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
@ -49,7 +56,7 @@ public class ForgeEventProcessor {
|
||||
private byte alphaDir = 1;
|
||||
protected int foodIconsOffset;
|
||||
|
||||
public static final ResourceLocation modIcons = new ResourceLocation(KamiMod.MODID, "textures/hungeroverlay.png");
|
||||
public static final ResourceLocation icons = new ResourceLocation(KamiMod.MODID, "textures/hungeroverlay.png");
|
||||
|
||||
@SubscribeEvent
|
||||
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
|
||||
@ -79,18 +86,21 @@ public class ForgeEventProcessor {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) {
|
||||
return;
|
||||
}
|
||||
|
||||
flashAlpha += alphaDir * 0.125F;
|
||||
if (MODULE_MANAGER.getModuleT(HungerOverlay.class).isEnabled()) {
|
||||
if (event.phase != TickEvent.Phase.END) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flashAlpha >= 1.5F) {
|
||||
flashAlpha = 1F;
|
||||
alphaDir = -1;
|
||||
} else if (flashAlpha <= -0.5F) {
|
||||
flashAlpha = 0F;
|
||||
alphaDir = 1;
|
||||
flashAlpha += alphaDir * 0.125F;
|
||||
|
||||
if (flashAlpha >= 1.5F) {
|
||||
flashAlpha = 1F;
|
||||
alphaDir = -1;
|
||||
} else if (flashAlpha <= -0.5F) {
|
||||
flashAlpha = 0F;
|
||||
alphaDir = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Wrapper.getPlayer() == null) return;
|
||||
@ -109,6 +119,32 @@ public class ForgeEventProcessor {
|
||||
if (event.getType() == RenderGameOverlayEvent.ElementType.BOSSINFO && MODULE_MANAGER.isModuleEnabled(BossStack.class)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
if (MODULE_MANAGER.getModuleT(HungerOverlay.class).isEnabled()) {
|
||||
if (event.getType() != RenderGameOverlayEvent.ElementType.FOOD) {
|
||||
return;
|
||||
}
|
||||
|
||||
foodIconsOffset = GuiIngameForge.right_height;
|
||||
|
||||
if (event.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MODULE_MANAGER.getModuleT(HungerOverlay.class).foodExhaustionOverlay.getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
EntityPlayer player = mc.player;
|
||||
|
||||
ScaledResolution scale = event.getResolution();
|
||||
|
||||
int left = scale.getScaledWidth() / 2 + 91;
|
||||
int top = scale.getScaledHeight() - foodIconsOffset;
|
||||
|
||||
HungerOverlayRenderHelper.drawExhaustionOverlay(HungerOverlayUtils.getExhaustion(player), mc, left, top, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@ -128,6 +164,52 @@ public class ForgeEventProcessor {
|
||||
} else if (event.getType() == RenderGameOverlayEvent.ElementType.BOSSINFO && MODULE_MANAGER.isModuleEnabled(BossStack.class)) {
|
||||
BossStack.render(event);
|
||||
}
|
||||
|
||||
if (MODULE_MANAGER.getModuleT(HungerOverlay.class).isEnabled()) {
|
||||
if (event.getType() != RenderGameOverlayEvent.ElementType.FOOD) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MODULE_MANAGER.getModuleT(HungerOverlay.class).foodValueOverlay.getValue() && !MODULE_MANAGER.getModuleT(HungerOverlay.class).saturationOverlay.getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
EntityPlayer player = mc.player;
|
||||
ItemStack heldItem = player.getHeldItemMainhand();
|
||||
FoodStats stats = player.getFoodStats();
|
||||
|
||||
ScaledResolution scale = event.getResolution();
|
||||
|
||||
int left = scale.getScaledWidth() / 2 + 91;
|
||||
int top = scale.getScaledHeight() - foodIconsOffset;
|
||||
|
||||
if (MODULE_MANAGER.getModuleT(HungerOverlay.class).saturationOverlay.getValue()) {
|
||||
HungerOverlayRenderHelper.drawSaturationOverlay(0, stats.getSaturationLevel(), mc, left, top, 1f);
|
||||
}
|
||||
|
||||
if (!MODULE_MANAGER.getModuleT(HungerOverlay.class).foodValueOverlay.getValue() || heldItem.isEmpty() || !HungerOverlayUtils.isFood(heldItem)) {
|
||||
flashAlpha = 0;
|
||||
alphaDir = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
HungerOverlayUtils.BasicFoodValues foodValues = HungerOverlayUtils.getDefaultFoodValues(heldItem);
|
||||
|
||||
HungerOverlayRenderHelper.drawHungerOverlay(foodValues.hunger, stats.getFoodLevel(), mc, left, top, flashAlpha);
|
||||
|
||||
if (MODULE_MANAGER.getModuleT(HungerOverlay.class).saturationOverlay.getValue()) {
|
||||
int newFoodValue = stats.getFoodLevel() + foodValues.hunger;
|
||||
float newSaturationValue = stats.getSaturationLevel() + foodValues.getSaturationIncrement();
|
||||
|
||||
HungerOverlayRenderHelper.drawSaturationOverlay(newSaturationValue > newFoodValue ? newFoodValue - stats.getSaturationLevel() : foodValues.getSaturationIncrement(), stats.getSaturationLevel(), mc, left, top, flashAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
|
||||
|
@ -0,0 +1,21 @@
|
||||
package me.zeroeightsix.kami.module.modules.misc;
|
||||
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.Settings;
|
||||
|
||||
/**
|
||||
* Created (partly) by Dewy on the 19th of April, 2020
|
||||
*
|
||||
* PLEASE NOTE: Just like xray, the overlay textures will break in a development environment.
|
||||
*/
|
||||
@Module.Info(
|
||||
name = "HungerOverlay",
|
||||
description = "Displays a helpful overlay over your hunger bar.",
|
||||
category = Module.Category.MISC
|
||||
)
|
||||
public class HungerOverlay extends Module {
|
||||
public Setting<Boolean> saturationOverlay = register(Settings.booleanBuilder("Saturation Overlay").withValue(true));
|
||||
public Setting<Boolean> foodValueOverlay = register(Settings.booleanBuilder("Food Value Overlay").withValue(true));
|
||||
public Setting<Boolean> foodExhaustionOverlay = register(Settings.booleanBuilder("Food Exhaustion Overlay").withValue(true));
|
||||
}
|
@ -6,7 +6,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.init.MobEffects;
|
||||
|
||||
public class HungerOverlayHelper {
|
||||
public class HungerOverlayRenderHelper {
|
||||
|
||||
public static void drawSaturationOverlay(float saturationGained, float saturationLevel, Minecraft mc, int left, int top, float alpha) {
|
||||
if (saturationLevel + saturationGained < 0) {
|
||||
@ -17,7 +17,7 @@ public class HungerOverlayHelper {
|
||||
int endBar = (int) Math.ceil(Math.min(20, saturationLevel + saturationGained) / 2f);
|
||||
int barsNeeded = endBar - startBar;
|
||||
|
||||
mc.getTextureManager().bindTexture(ForgeEventProcessor.modIcons);
|
||||
mc.getTextureManager().bindTexture(ForgeEventProcessor.icons);
|
||||
|
||||
RenderHelper.enableAlpha(alpha);
|
||||
|
||||
@ -80,7 +80,7 @@ public class HungerOverlayHelper {
|
||||
}
|
||||
|
||||
public static void drawExhaustionOverlay(float exhaustion, Minecraft mc, int left, int top, float alpha) {
|
||||
mc.getTextureManager().bindTexture(ForgeEventProcessor.modIcons);
|
||||
mc.getTextureManager().bindTexture(ForgeEventProcessor.icons);
|
||||
|
||||
float maxExhaustion = HungerOverlayUtils.getMaxExhaustion(mc.player);
|
||||
float ratio = exhaustion / maxExhaustion;
|
BIN
src/main/resources/assets/kamiblue/textures/hungeroverlay.png
Normal file
BIN
src/main/resources/assets/kamiblue/textures/hungeroverlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 480 B |
Loading…
Reference in New Issue
Block a user