Add Potion.renderHUDEffect (#2798)

This commit is contained in:
Vincent Lee 2016-05-02 16:44:14 -05:00 committed by LexManos
parent d9bdaef468
commit 9f28c90365
3 changed files with 76 additions and 1 deletions

View file

@ -10,3 +10,26 @@
{
return;
}
@@ -418,7 +419,10 @@
{
Potion potion = potioneffect.func_188419_a();
- if (potion.func_76400_d() && potioneffect.func_188418_e())
+ if (!potion.shouldRenderHUD(potioneffect)) continue;
+ // Rebind in case previous renderHUDEffect changed texture
+ this.field_73839_d.func_110434_K().func_110577_a(GuiContainer.field_147001_a);
+ if (potioneffect.func_188418_e())
{
int k = p_184048_1_.func_78326_a();
int l = 1;
@@ -455,7 +459,10 @@
}
GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, f);
+ // FORGE - Move status icon check down from above so renderHUDEffect will still be called without a status icon
+ if (potion.func_76400_d())
this.func_73729_b(k + 3, l + 3, i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
+ potion.renderHUDEffect(k, l, potioneffect, field_73839_d, f);
}
}
}

View file

@ -20,7 +20,7 @@
public boolean func_76398_f()
{
return this.field_76418_K;
@@ -266,7 +265,37 @@
@@ -266,7 +265,61 @@
return p_111183_2_.func_111164_d() * (double)(p_111183_1_ + 1);
}
@ -44,6 +44,16 @@
+ }
+
+ /**
+ * If the Potion effect should be displayed in the player's ingame HUD
+ * @param effect the active PotionEffect
+ * @return true to display it (default), false to hide it.
+ */
+ public boolean shouldRenderHUD(PotionEffect effect)
+ {
+ return true;
+ }
+
+ /**
+ * Called to draw the this Potion onto the player's inventory when it's active.
+ * This can be used to e.g. render Potion icons from your own texture.
+ * @param x the x coordinate
@ -54,6 +64,20 @@
@SideOnly(Side.CLIENT)
+ public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc) { }
+
+ /**
+ * Called to draw the this Potion onto the player's ingame HUD when it's active.
+ * This can be used to e.g. render Potion icons from your own texture.
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param effect the active PotionEffect
+ * @param mc the Minecraft instance, for convenience
+ * @param alpha the alpha value, blinks when the potion is about to run out
+ */
+ @SideOnly(Side.CLIENT)
+ public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha) { }
+
+ /* ======================================== FORGE END =====================================*/
+
+ @SideOnly(Side.CLIENT)
public boolean func_188408_i()
{

View file

@ -84,5 +84,33 @@ public class PotionRegistryDebug {
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw();
}
@Override
public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha) {
Potion potion = effect.getPotion();
mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
x += 3;
y += 3;
int width = 18;
int height = width;
float r = (float)(potion.getLiquidColor() >> 24 & 255) / 255.0F;
float g = (float)(potion.getLiquidColor() >> 16 & 255) / 255.0F;
float b = (float)(potion.getLiquidColor() >> 8 & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buf = tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
GlStateManager.color(r, g, b, alpha);
buf.pos((double) x, (double)(y + height), 0.0D).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
buf.pos((double)(x + width), (double)(y + height), 0.0D).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
buf.pos((double)(x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw();
}
}
}