From 8fffdf110f800162c370f1d4bc2e68196d72362b Mon Sep 17 00:00:00 2001 From: Markil3 <75867393+Markil3@users.noreply.github.com> Date: Sat, 27 Feb 2021 11:00:20 -0700 Subject: [PATCH] Makes potion icons fade over time. --- .../java/markil3/immersive_hud/EventBus.java | 18 +++ .../markil3/immersive_hud/RenderUtils.java | 130 ++++++++++++++++-- .../markil3/immersive_hud/TimerUtils.java | 66 +++++++++ 3 files changed, 202 insertions(+), 12 deletions(-) diff --git a/src/main/java/markil3/immersive_hud/EventBus.java b/src/main/java/markil3/immersive_hud/EventBus.java index c9e89c3..7d23460 100644 --- a/src/main/java/markil3/immersive_hud/EventBus.java +++ b/src/main/java/markil3/immersive_hud/EventBus.java @@ -140,6 +140,24 @@ public class EventBus resetAlpha(); } break; + case POTION_ICONS: + if (event instanceof RenderGameOverlayEvent.Pre) + { + TimerUtils.updatePotions(mc.player); + event.setCanceled(true); + RenderUtils.renderPotionIcons(mc, + mc.ingameGUI, + event.getMatrixStack()); + resetAlpha(); + } + /* + * Reset the transparency. + */ + else if (event instanceof RenderGameOverlayEvent.Post) + { + resetAlpha(); + } + break; case HOTBAR: if (event instanceof RenderGameOverlayEvent.Pre) { diff --git a/src/main/java/markil3/immersive_hud/RenderUtils.java b/src/main/java/markil3/immersive_hud/RenderUtils.java index 03520f5..1f41ab9 100644 --- a/src/main/java/markil3/immersive_hud/RenderUtils.java +++ b/src/main/java/markil3/immersive_hud/RenderUtils.java @@ -1,32 +1,36 @@ /** * Copyright (C) 2009-2021 Mojang Studios - * - * Players are free to create, build, and mod within Minecraft if the - * branding usage guidelines are followed. Fan art, logos, videos, and screen - * shots are acceptable as long as they are not used to falsely represent - * Mojang Minecraft assets. If you intend to use any portion of the name in - * relation to services, products, or distribution, you must adhere to the - * following requirements. - * - * Mojang's terms of service and brand guidelines are designed to let you - * know in plain terms what you can and cannot do with your game, the Mojang - * brand or Mojang assets. - * https://account.mojang.com/documents/minecraft_eula + *
+ * Players are free to create, build, and mod within Minecraft if the branding + * usage guidelines are followed. Fan art, logos, videos, and screen shots are + * acceptable as long as they are not used to falsely represent Mojang Minecraft + * assets. If you intend to use any portion of the name in relation to + * services, products, or distribution, you must adhere to the following + * requirements. + *
+ * Mojang's terms of service and brand guidelines are designed to let you know
+ * in plain terms what you can and cannot do with your game, the Mojang brand or
+ * Mojang assets. https://account.mojang.com/documents/minecraft_eula
*/
package markil3.immersive_hud;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.IngameGui;
+import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
+import net.minecraft.client.renderer.texture.PotionSpriteUploader;
+import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.settings.AttackIndicatorStatus;
import net.minecraft.crash.CrashReport;
@@ -35,10 +39,16 @@ import net.minecraft.crash.ReportedException;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
+import net.minecraft.potion.Effect;
+import net.minecraft.potion.EffectInstance;
import net.minecraft.util.HandSide;
import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
+import java.util.Collection;
+import java.util.List;
+
/**
* Contains methods for rendering various HUD elements. Most of these methods
* come from {@link IngameGui} and
@@ -50,6 +60,102 @@ import net.minecraft.world.World;
*/
public class RenderUtils
{
+ public static void renderPotionIcons(Minecraft mc,
+ IngameGui gui,
+ MatrixStack matrixStack)
+ {
+ int scaledWidth = mc.getMainWindow().getScaledWidth();
+ int scaledHeight = mc.getMainWindow().getScaledHeight();
+
+ Collection