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

This commit is contained in:
Ben Staddon authored and tterrag committed 2019-04-12 11:05:34 -04:00
1 parent d20b1f271e
commit e376172312
4 files changed
+50 -64

No files matched your search

@@ -19,9 +19,8 @@
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.gui.Gui;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
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.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import java.util.Random;
@Mod(modid = PotionRegistryTest.MODID, name = "ForgePotionRegistry", version = "1.0", acceptableRemoteVersions = "*")
@Mod.EventBusSubscriber
@Mod(modid = PotionRegistryTest.MOD_ID, name = "ForgePotionRegistry", version = "1.0", acceptableRemoteVersions = "*")
public class PotionRegistryTest
{
public static final String MODID = "forgepotionregistry";
public static final String MOD_ID = "forge_potion_registry";
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
@SubscribeEvent
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
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00).setRegistryName(new ResourceLocation(MODID, "forgy")); // test that ids above 127 work
ForgeRegistries.POTIONS.register(forge);
//((ForgeRegistry)ForgeRegistries.POTIONS).register(200, forgy.getRegistryName(), forgy);
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);
}
event.getRegistry().register(
new PotionForge(false, 0xff00ff)
.setRegistryName(MOD_ID, "forge")
.setPotionName("potion." + MOD_ID + ".forge")
);
}
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);
setPotionName("potion." + location.getResourcePath());
}
@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();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0");
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0");
x += 6;
y += 7;
@@ -101,22 +81,25 @@ public class PotionRegistryTest
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buf = tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
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 + 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();
buf.pos((double) x, (double) (y + height), z).tex(sprite.getMinU(), 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, z).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
buf.pos((double) x, (double) y, z).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw();
}
@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();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
x += 3;
y += 3;
@@ -130,12 +113,12 @@ public class PotionRegistryTest
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buf = tessellator.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
buf.begin(GL11.GL_QUADS, 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();
buf.pos((double) x, (double) (y + height), z).tex(sprite.getMinU(), 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, z).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
buf.pos((double) x, (double) y, z).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
tessellator.draw();
}
}