Improve context provided by potion icon rendering hooks (#5111)

This commit is contained in:
Ben Staddon 2019-04-12 11:05:34 -04:00 committed by tterrag
parent d20b1f271e
commit e376172312
4 changed files with 50 additions and 64 deletions

View File

@ -28,7 +28,7 @@
+ // FORGE - Move status icon check down from above so renderHUDEffect will still be called without a status icon + // FORGE - Move status icon check down from above so renderHUDEffect will still be called without a status icon
+ if (potion.func_76400_d()) + if (potion.func_76400_d())
this.func_73729_b(k + 3, l + 3, l1 * 18, 198 + k1 * 18, 18, 18); this.func_73729_b(k + 3, l + 3, l1 * 18, 198 + k1 * 18, 18, 18);
+ potion.renderHUDEffect(k, l, potioneffect, field_73839_d, f); + potion.renderHUDEffect(potioneffect, this, k, l, this.field_73735_i, f);
} }
} }

View File

@ -30,7 +30,7 @@
this.func_73729_b(i + 6, j + 7, i1 % 12 * 18, 198 + i1 / 12 * 18, 18, 18); this.func_73729_b(i + 6, j + 7, i1 % 12 * 18, 198 + i1 / 12 * 18, 18, 18);
} }
+ potion.renderInventoryEffect(i, j, potioneffect, field_146297_k); + potion.renderInventoryEffect(potioneffect, this, i, j, this.field_73735_i);
+ if (!potion.shouldRenderInvText(potioneffect)) { j += l; continue; } + if (!potion.shouldRenderInvText(potioneffect)) { j += l; continue; }
String s1 = I18n.func_135052_a(potion.func_76393_a()); String s1 = I18n.func_135052_a(potion.func_76393_a());
if (potioneffect.func_76458_c() == 1) { if (potioneffect.func_76458_c() == 1) {

View File

@ -17,7 +17,7 @@
public boolean func_76398_f() { public boolean func_76398_f() {
return this.field_76418_K; return this.field_76418_K;
} }
@@ -258,4 +257,70 @@ @@ -258,4 +257,73 @@
private static void func_210759_a(int p_210759_0_, String p_210759_1_, Potion p_210759_2_) { private static void func_210759_a(int p_210759_0_, String p_210759_1_, Potion p_210759_2_) {
IRegistry.field_212631_t.func_177775_a(p_210759_0_, new ResourceLocation(p_210759_1_), p_210759_2_); IRegistry.field_212631_t.func_177775_a(p_210759_0_, new ResourceLocation(p_210759_1_), p_210759_2_);
} }
@ -46,25 +46,28 @@
+ /** + /**
+ * Called to draw the this Potion onto the player's inventory when it's active. + * 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. + * This can be used to e.g. render Potion icons from your own texture.
+ *
+ * @param effect the active PotionEffect
+ * @param gui the gui instance
+ * @param x the x coordinate + * @param x the x coordinate
+ * @param y the y coordinate + * @param y the y coordinate
+ * @param effect the active PotionEffect + * @param z the z level
+ * @param mc the Minecraft instance, for convenience
+ */ + */
+ @OnlyIn(Dist.CLIENT) + @OnlyIn(Dist.CLIENT)
+ public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc) { } + public void renderInventoryEffect(PotionEffect effect, net.minecraft.client.gui.Gui gui, int x, int y, float z) { }
+ +
+ /** + /**
+ * Called to draw the this Potion onto the player's ingame HUD when it's active. + * 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. + * This can be used to e.g. render Potion icons from your own texture.
+ * @param effect the active PotionEffect
+ * @param gui the gui instance
+ * @param x the x coordinate + * @param x the x coordinate
+ * @param y the y coordinate + * @param y the y coordinate
+ * @param effect the active PotionEffect + * @param z the z level
+ * @param mc the Minecraft instance, for convenience
+ * @param alpha the alpha value, blinks when the potion is about to run out + * @param alpha the alpha value, blinks when the potion is about to run out
+ */ + */
+ @OnlyIn(Dist.CLIENT) + @OnlyIn(Dist.CLIENT)
+ public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha) { } + public void renderHUDEffect(PotionEffect effect, net.minecraft.client.gui.Gui gui, int x, int y, float z, float alpha) { }
+ +
+ /** + /**
+ * Get a fresh list of items that can cure this Potion. + * Get a fresh list of items that can cure this Potion.

View File

@ -19,9 +19,8 @@
package net.minecraftforge.debug.gameplay; package net.minecraftforge.debug.gameplay;
import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
@ -30,63 +29,44 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import java.util.Random; @Mod.EventBusSubscriber
@Mod(modid = PotionRegistryTest.MOD_ID, name = "ForgePotionRegistry", version = "1.0", acceptableRemoteVersions = "*")
@Mod(modid = PotionRegistryTest.MODID, name = "ForgePotionRegistry", version = "1.0", acceptableRemoteVersions = "*")
public class PotionRegistryTest public class PotionRegistryTest
{ {
public static final String MODID = "forgepotionregistry"; public static final String MOD_ID = "forge_potion_registry";
@Mod.EventHandler @SubscribeEvent
public void preInit(FMLPreInitializationEvent event) public static void registerPotions(RegistryEvent.Register<Potion> event)
{ {
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff).setRegistryName(new ResourceLocation(MODID, "forge")); // test automatic id distribution event.getRegistry().register(
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00).setRegistryName(new ResourceLocation(MODID, "forgy")); // test that ids above 127 work new PotionForge(false, 0xff00ff)
ForgeRegistries.POTIONS.register(forge); .setRegistryName(MOD_ID, "forge")
//((ForgeRegistry)ForgeRegistries.POTIONS).register(200, forgy.getRegistryName(), forgy); .setPotionName("potion." + MOD_ID + ".forge")
);
Random rand = new Random();
TIntSet taken = new TIntHashSet(100);
int ra = rand.nextInt(100) + 100;
taken.add(ra);
// a new potion with a random id so that forge has to remap it
//new PotionForge(ra, new ResourceLocation(ForgeMod.MOD_ID, "realRandomPotion"), false, 0x0000ff);
for (int i = 0; i < 20; i++)
{
int r = rand.nextInt(200) + 35;
while (taken.contains(r))
r = rand.nextInt(200) + 35;
//r = 32+i;
taken.add(r);
// this potions will most likely not have the same IDs between server and client.
// The forge handshake on connect should fix this.
//new PotionForge(new ResourceLocation(ForgeMod.MOD_ID, "randomPotion" + r), false, 0xff00ff);
}
} }
protected class PotionForge extends Potion private static class PotionForge extends Potion
{ {
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor) PotionForge(boolean badEffect, int potionColor)
{ {
super(badEffect, potionColor); super(badEffect, potionColor);
setPotionName("potion." + location.getResourcePath());
} }
@Override @Override
public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc) @SideOnly(Side.CLIENT)
public void renderInventoryEffect(PotionEffect effect, Gui gui, int x, int y, float z)
{ {
Potion potion = effect.getPotion(); Potion potion = effect.getPotion();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0"); TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0");
x += 6; x += 6;
y += 7; y += 7;
@ -101,22 +81,25 @@ public class PotionRegistryTest
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buf = tessellator.getBuffer(); BufferBuilder buf = tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX); buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
GlStateManager.color(r, g, b, a); GlStateManager.color(r, g, b, a);
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, (double) (y + height), z).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
buf.pos((double) (x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex(); buf.pos((double) (x + width), (double) (y + height), z).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex(); buf.pos((double) (x + width), (double) y, z).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
buf.pos((double) x, (double) y, z).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw(); tessellator.draw();
} }
@Override @Override
public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha) @SideOnly(Side.CLIENT)
public void renderHUDEffect(PotionEffect effect, Gui gui, int x, int y, float z, float alpha)
{ {
Potion potion = effect.getPotion(); Potion potion = effect.getPotion();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side"); TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
x += 3; x += 3;
y += 3; y += 3;
@ -130,12 +113,12 @@ public class PotionRegistryTest
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buf = tessellator.getBuffer(); BufferBuilder buf = tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX); buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
GlStateManager.color(r, g, b, alpha); 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, (double) (y + height), z).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 + height), z).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 + width), (double) y, z).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex(); buf.pos((double) x, (double) y, z).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw(); tessellator.draw();
} }
} }