From 2324c2fd204ef6a51ef69f5b5729dabb0b724d4e Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Sun, 18 Oct 2015 21:40:52 +0200 Subject: [PATCH] Add shouldRender() to Potions that allows to hide them completely in the inventory --- .../InventoryEffectRenderer.java.patch | 24 ++++++++++++++- .../net/minecraft/potion/Potion.java.patch | 9 +++++- .../debug/NoPotionEffectRenderTest.java | 29 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java diff --git a/patches/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch b/patches/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch index fd3e46ca8..74f00edc5 100644 --- a/patches/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch @@ -1,6 +1,28 @@ --- ../src-base/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java +++ ../src-work/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java -@@ -80,6 +80,8 @@ +@@ -27,7 +27,12 @@ + + protected void func_175378_g() + { +- if (!this.field_146297_k.field_71439_g.func_70651_bq().isEmpty()) ++ boolean hasVisibleEffect = false; ++ for(PotionEffect potioneffect : this.field_146297_k.field_71439_g.func_70651_bq()) { ++ Potion potion = Potion.field_76425_a[potioneffect.func_76456_a()]; ++ if(potion.shouldRender(potioneffect)) { hasVisibleEffect = true; break; } ++ } ++ if (!this.field_146297_k.field_71439_g.func_70651_bq().isEmpty() && hasVisibleEffect) + { + this.field_147003_i = 160 + (this.field_146294_l - this.field_146999_f - 200) / 2; + this.field_147045_u = true; +@@ -70,6 +75,7 @@ + for (PotionEffect potioneffect : this.field_146297_k.field_71439_g.func_70651_bq()) + { + Potion potion = Potion.field_76425_a[potioneffect.func_76456_a()]; ++ if(!potion.shouldRender(potioneffect)) continue; + GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146297_k.func_110434_K().func_110577_a(field_147001_a); + this.func_73729_b(i, j, 0, 166, 140, 32); +@@ -80,6 +86,8 @@ this.func_73729_b(i + 6, j + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18); } diff --git a/patches/minecraft/net/minecraft/potion/Potion.java.patch b/patches/minecraft/net/minecraft/potion/Potion.java.patch index 05ec68e23..1ee629dcc 100644 --- a/patches/minecraft/net/minecraft/potion/Potion.java.patch +++ b/patches/minecraft/net/minecraft/potion/Potion.java.patch @@ -51,7 +51,7 @@ public boolean func_76398_f() { return this.field_76418_K; -@@ -310,4 +313,27 @@ +@@ -310,4 +313,34 @@ { return p_111183_2_.func_111164_d() * (double)(p_111183_1_ + 1); } @@ -59,6 +59,13 @@ + /* ======================================== FORGE START =====================================*/ + + /** ++ * If the Potion effect should be displayed in the players inventory ++ * @param effect the active PotionEffect ++ * @return true to display it (default), false to hide it. ++ */ ++ public boolean shouldRender(PotionEffect effect) { return true; } ++ ++ /** + * If the standard PotionEffect text (name and duration) should be drawn when this potion is active. + * @param effect the active PotionEffect + * @return true to draw the standard text diff --git a/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java b/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java new file mode 100644 index 000000000..f8d779140 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java @@ -0,0 +1,29 @@ +package net.minecraftforge.debug; + +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +@Mod( modid = NoPotionEffectRenderTest.modID, name = "No Potion Effect Render Test", version = "0.0.0" ) +public class NoPotionEffectRenderTest { + public static final String modID = "nopotioneffect"; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) { + TestPotion INSTANCE = new TestPotion(30, new ResourceLocation(modID, "test_potion"), false, 0xff00ff); + } + + public static class TestPotion extends Potion { + + public TestPotion(int potionID, ResourceLocation location, boolean badEffect, int potionColor) { + super(potionID, location, badEffect, potionColor); + } + + @Override + public boolean shouldRender(PotionEffect effect) { + return false; + } + } +}