Rewrote IItemRenderer to be a more generic and expandable version, Breaks previous interfaces, but this should be the last time the interface changes.

Implemented the MapRender hook ChickenBones requested.
This commit is contained in:
LexManos 2012-04-09 22:57:52 -07:00
parent e400b2df4e
commit 20e264f9ee
7 changed files with 164 additions and 94 deletions

View file

@ -19,6 +19,9 @@ import java.util.*;
import net.minecraft.src.*; import net.minecraft.src.*;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import static net.minecraft.src.forge.IItemRenderer.ItemRenderType.*;
import static net.minecraft.src.forge.IItemRenderer.ItemRendererHelper.*;
public class ForgeHooksClient public class ForgeHooksClient
{ {
@ -261,18 +264,13 @@ public class ForgeHooksClient
} }
} }
public static void renderEntityItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityItem item)
{
customRenderer.renderEntityItem(renderBlocks, item);
}
public static void renderEquippedItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityLiving entity, ItemStack item) public static void renderEquippedItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityLiving entity, ItemStack item)
{ {
if (customRenderer.renderEquippedItemAsBlock(item)) if (customRenderer.shouldUseRenderHelper(EQUIPPED, item, EQUIPPED_BLOCK))
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef(-0.5F, -0.5F, -0.5F); GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
customRenderer.renderEquippedItem(renderBlocks, entity, item); customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
else else
@ -284,14 +282,9 @@ public class ForgeHooksClient
GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F); GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F); GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
customRenderer.renderEquippedItem(renderBlocks, entity, item); customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity);
GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }
public static void renderInventoryItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, ItemStack item)
{
customRenderer.renderInventoryItem(renderBlocks, item);
}
} }

View file

@ -7,7 +7,86 @@ import net.minecraft.src.RenderBlocks;
public interface IItemRenderer public interface IItemRenderer
{ {
/** Checks if this renderer should handle a specific item's render type public enum ItemRenderType
{
/**
* Called to render an in-world item, e.g. one that has been thrown or
* dropped. The appropriate OpenGL transformations and scaling have already
* been applied, so Tessellator location (0,0,0) is the center of the
* EntityItem.
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
* EntityItem entity - The in-world item to be rendered
*/
ENTITY,
/**
* Called to render an item currently held in-hand by a living entity. If
* rendering as a 3D block, the item will be rotated to a 45-degree angle.
* To render a 2D texture with some thickness (like default items), see
* net.minecraft.src.ItemRenderer. In either case, rendering should be done
* in local coordinates from (0,0,0)-(1,1,1).
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
* EntityLiving entity - The entity holding this item
*/
EQUIPPED,
/**
* Called to render an item in a GUI inventory slot. If rendering as a 3D
* block, the appropriate OpenGL translations and scaling have already been
* applied, and the rendering should be done in local coordinates from
* (0,0,0)-(1,1,1). If rendering as a 2D texture, the rendering should be in
* GUI pixel coordinates from (0, 0, 0)-(16, 16, 0).
*
* Data parameters:
* RenderBlocks render - The RenderBlocks instance
*/
INVENTORY,
/**
* The render type used for when a ItemMap is rendered in first person,
* All appropriate rotations have been applied, and the player's hands,
* and the map BG are already rendered.
*
* Data Parameters:
* EntityPlayer player - The player holding the map
* RenderEngine engine - The RenderEngine instance
* MapData mapData - The map data
*/
FIRST_PERSON_MAP
}
public enum ItemRendererHelper
{
/**
* Determines if a rotation effect should be used when rendering an
* EntityItem, like most default blocks do.
*/
ENTITY_ROTATION,
/**
* Determines if an up-and-down bobbing effect should be used when
*/
ENTITY_BOBBING,
/**
* Determines if the currently equipped item should be rendered as a 3D
* block or as a 2D texture.
*/
EQUIPPED_BLOCK,
/**
* Determines if the item should be rendered in GUI inventory slots as a 3D
* block or as a 2D texture.
*/
INVENTORY_BLOCK
}
/**
* Checks if this renderer should handle a specific item's render type
* @param item The item we are trying to render * @param item The item we are trying to render
* @param type A render type to check if this renderer handles * @param type A render type to check if this renderer handles
* @return true if this renderer should handle the given render type, * @return true if this renderer should handle the given render type,
@ -15,64 +94,24 @@ public interface IItemRenderer
*/ */
public boolean handleRenderType(ItemStack item, ItemRenderType type); public boolean handleRenderType(ItemStack item, ItemRenderType type);
/** Called to render an in-world item, e.g. one that has been thrown or /**
* dropped. The appropriate OpenGL transformations and scaling have already * Checks if certain helper functionality should be executed for this renderer.
* been applied, so Tessellator location (0,0,0) is the center of the * See ItemRendererHelper for more info
* EntityItem. *
* @param render The RenderBlocks instance * @param type The render type
* @param item The in-world item to be rendered * @param item The ItemStack being rendered
* @param helper The type of helper functionality to be ran
* @return True to run the helper functionality, false to not.
*/ */
public void renderEntityItem(RenderBlocks render, EntityItem item); public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper);
/** Determines if a rotation effect should be used when rendering an /**
* EntityItem, like most default blocks do. * Called to do the actual rendering, see ItemRenderType for details on when specific
* @param item the item we are trying to render * types are run, and what extra data is passed into the data parameter.
* @return true if the EntityItem should rotate, otherwise false *
* @param type The render type
* @param item The ItemStack being rendered
* @param data Extra Type specific data
*/ */
public boolean useEntityItemRotationEffect(ItemStack item); public void renderItem(ItemRenderType type, ItemStack item, Object... data);
/** Determines if an up-and-down bobbing effect should be used when
* rendering an EntityItem, like all default blocks and items do.
* @param item the item we are trying to render
* @return true if the EntityItem should bob up and down, otherwise false
*/
public boolean useEntityItemBobbingEffect(ItemStack item);
/** Called to render an item currently held in-hand by a living entity. If
* rendering as a 3D block, the item will be rotated to a 45-degree angle.
* To render a 2D texture with some thickness (like default items), see
* net.minecraft.src.ItemRenderer. In either case, rendering should be done
* in local coordinates from (0,0,0)-(1,1,1).
* @param render The RenderBlocks instance
* @param entity The entity holding this item
* @param item The equipped item to be rendered
*/
public void renderEquippedItem(RenderBlocks render, EntityLiving entity, ItemStack item);
/** Determines if the currently equipped item should be rendered as a 3D
* block or as a 2D texture.
* @param item the item we are trying to render
* @return true if the equipped item should be rendered as a 3D block,
* otherwise false
*/
public boolean renderEquippedItemAsBlock(ItemStack item);
/** Called to render an item in a GUI inventory slot. If rendering as a 3D
* block, the appropriate OpenGL translations and scaling have already been
* applied, and the rendering should be done in local coordinates from
* (0,0,0)-(1,1,1). If rendering as a 2D texture, the rendering should be in
* GUI pixel coordinates from (0, 0, 0)-(16, 16, 0).
* @param render The RenderBlocks instance
* @param item The item stack to render
*/
public void renderInventoryItem(RenderBlocks render, ItemStack item);
/** Determines if the item should be rendered in GUI inventory slots as a 3D
* block or as a 2D texture.
* @param item the item we are trying to render
* @return true if the inventory item should be rendered as a 3D block,
* otherwise false
*/
public boolean renderInventoryItemAsBlock(ItemStack item);
} }

View file

@ -1,5 +1,6 @@
package net.minecraft.src.forge; package net.minecraft.src.forge;
@Deprecated //Now consolidated into IITemRenderer
public enum ItemRenderType public enum ItemRenderType
{ {
ENTITY, // Render type for in-world EntityItems ENTITY, // Render type for in-world EntityItems

View file

@ -12,6 +12,7 @@ import net.minecraft.src.Item;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader; import net.minecraft.src.ModLoader;
import net.minecraft.src.RenderBlocks; import net.minecraft.src.RenderBlocks;
import net.minecraft.src.forge.IItemRenderer.ItemRenderType;
public class MinecraftForgeClient public class MinecraftForgeClient
{ {

View file

@ -603,9 +603,13 @@ public class ForgeHooks
} }
public static ArrayList<IArrowNockHandler> arrowNockHandlers = new ArrayList<IArrowNockHandler>(); public static ArrayList<IArrowNockHandler> arrowNockHandlers = new ArrayList<IArrowNockHandler>();
//This number is incremented every Minecraft version, and never reset
public static final int majorVersion = 3; public static final int majorVersion = 3;
//This number is incremented every official release, and reset every Minecraft version
public static final int minorVersion = 0; public static final int minorVersion = 0;
public static final int revisionVersion = 0; //This number is incremented every time a interface changes, and reset every Minecraft version
public static final int revisionVersion = 1;
//This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code.
public static final int buildVersion = 0; public static final int buildVersion = 0;
static static
{ {

View file

@ -1,22 +1,23 @@
--- ../src_base/minecraft/net/minecraft/src/ItemRenderer.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/ItemRenderer.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/ItemRenderer.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/ItemRenderer.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,6 +1,11 @@ @@ -1,6 +1,12 @@
package net.minecraft.src; package net.minecraft.src;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
+import net.minecraft.src.forge.ForgeHooksClient; +import net.minecraft.src.forge.ForgeHooksClient;
+import net.minecraft.src.forge.IItemRenderer; +import net.minecraft.src.forge.IItemRenderer;
+import net.minecraft.src.forge.ItemRenderType;
+import net.minecraft.src.forge.MinecraftForgeClient; +import net.minecraft.src.forge.MinecraftForgeClient;
+import static net.minecraft.src.forge.IItemRenderer.ItemRenderType.*;
+import static net.minecraft.src.forge.IItemRenderer.ItemRendererHelper.*;
+ +
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
@@ -35,21 +40,27 @@ @@ -35,21 +41,27 @@
public void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3) public void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3)
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
+ IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, ItemRenderType.EQUIPPED); + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, EQUIPPED);
- if (par2ItemStack.itemID < 256 && RenderBlocks.renderItemIn3d(Block.blocksList[par2ItemStack.itemID].getRenderType())) - if (par2ItemStack.itemID < 256 && RenderBlocks.renderItemIn3d(Block.blocksList[par2ItemStack.itemID].getRenderType()))
+ if (customRenderer != null) + if (customRenderer != null)
@ -44,3 +45,33 @@
} }
Tessellator var4 = Tessellator.instance; Tessellator var4 = Tessellator.instance;
@@ -246,8 +258,10 @@
float var11;
float var13;
- if (var14 != null && var14.itemID == Item.map.shiftedIndex)
+ if (var14 != null && var14.getItem() instanceof ItemMap)
{
+ IItemRenderer custom = MinecraftForgeClient.getItemRenderer(var14, FIRST_PERSON_MAP);
+
GL11.glPushMatrix();
var7 = 0.8F;
var17 = var3.getSwingProgress(par1);
@@ -313,8 +327,15 @@
var26.addVertexWithUV((double)(128 + var27), (double)(0 - var27), 0.0D, 1.0D, 0.0D);
var26.addVertexWithUV((double)(0 - var27), (double)(0 - var27), 0.0D, 0.0D, 0.0D);
var26.draw();
- MapData var23 = Item.map.getMapData(var14, this.mc.theWorld);
- this.mapItemRenderer.renderMap(this.mc.thePlayer, this.mc.renderEngine, var23);
+ MapData var23 = ((ItemMap)var14.getItem()).getMapData(var14, this.mc.theWorld);
+ if (custom == null)
+ {
+ this.mapItemRenderer.renderMap(this.mc.thePlayer, this.mc.renderEngine, var23);
+ }
+ else
+ {
+ custom.renderItem(FIRST_PERSON_MAP, var14, mc.thePlayer, mc.renderEngine, var23);
+ }
GL11.glPopMatrix();
}
else if (var14 != null)

View file

@ -1,32 +1,33 @@
--- ../src_base/minecraft/net/minecraft/src/RenderItem.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/RenderItem.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/RenderItem.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/RenderItem.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,6 +1,12 @@ @@ -1,6 +1,13 @@
package net.minecraft.src; package net.minecraft.src;
import java.util.Random; import java.util.Random;
+ +
+import net.minecraft.src.forge.ForgeHooksClient; +import net.minecraft.src.forge.ForgeHooksClient;
+import net.minecraft.src.forge.IItemRenderer; +import net.minecraft.src.forge.IItemRenderer;
+import net.minecraft.src.forge.ItemRenderType;
+import net.minecraft.src.forge.MinecraftForgeClient; +import net.minecraft.src.forge.MinecraftForgeClient;
+import static net.minecraft.src.forge.IItemRenderer.ItemRenderType.*;
+import static net.minecraft.src.forge.IItemRenderer.ItemRendererHelper.*;
+ +
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
@@ -55,10 +61,58 @@ @@ -55,10 +62,58 @@
float var18; float var18;
float var23; float var23;
- if (var10.itemID < 256 && RenderBlocks.renderItemIn3d(Block.blocksList[var10.itemID].getRenderType())) - if (var10.itemID < 256 && RenderBlocks.renderItemIn3d(Block.blocksList[var10.itemID].getRenderType()))
+ IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var10, ItemRenderType.ENTITY); + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var10, ENTITY);
+ +
+ if (customRenderer != null) + if (customRenderer != null)
+ { + {
+ if (customRenderer.useEntityItemRotationEffect(var10)) + if (customRenderer.shouldUseRenderHelper(ENTITY, var10, ENTITY_ROTATION))
+ { + {
+ GL11.glRotatef(var12, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(var12, 0.0F, 1.0F, 0.0F);
+ } + }
+ if (!customRenderer.useEntityItemBobbingEffect(var10)) + if (!customRenderer.shouldUseRenderHelper(ENTITY, var10, ENTITY_BOBBING))
+ { + {
+ GL11.glTranslatef(0.0F, -var11, 0.0F); + GL11.glTranslatef(0.0F, -var11, 0.0F);
+ } + }
@ -54,7 +55,7 @@
+ ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F, + ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F,
+ ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F); + ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F);
+ } + }
+ ForgeHooksClient.renderEntityItem(customRenderer, renderBlocks, par1EntityItem); + customRenderer.renderItem(ENTITY, var10, renderBlocks, par1EntityItem);
+ GL11.glPopMatrix(); + GL11.glPopMatrix();
+ } + }
+ } + }
@ -62,7 +63,7 @@
+ { + {
+ this.loadTexture(ForgeHooksClient.getTexture(var10.itemID < 256 ? "/terrain.png" : "/gui/items.png", var10.getItem())); + this.loadTexture(ForgeHooksClient.getTexture(var10.itemID < 256 ? "/terrain.png" : "/gui/items.png", var10.getItem()));
+ GL11.glScalef(0.5F, 0.5F, 0.5F); + GL11.glScalef(0.5F, 0.5F, 0.5F);
+ ForgeHooksClient.renderEntityItem(customRenderer, renderBlocks, par1EntityItem); + customRenderer.renderItem(ENTITY, var10, renderBlocks, par1EntityItem);
+ } + }
+ +
+ } + }
@ -74,7 +75,7 @@
float var21 = 0.25F; float var21 = 0.25F;
var15 = Block.blocksList[var10.itemID].getRenderType(); var15 = Block.blocksList[var10.itemID].getRenderType();
@@ -94,7 +148,7 @@ @@ -94,7 +149,7 @@
if (var10.getItem().func_46058_c()) if (var10.getItem().func_46058_c())
{ {
GL11.glScalef(0.5F, 0.5F, 0.5F); GL11.glScalef(0.5F, 0.5F, 0.5F);
@ -83,7 +84,7 @@
for (var14 = 0; var14 <= 1; ++var14) for (var14 = 0; var14 <= 1; ++var14)
{ {
@@ -120,11 +174,11 @@ @@ -120,11 +175,11 @@
if (var10.itemID < 256) if (var10.itemID < 256)
{ {
@ -97,7 +98,7 @@
} }
if (this.field_27004_a) if (this.field_27004_a)
@@ -186,10 +240,10 @@ @@ -186,10 +241,10 @@
float var11; float var11;
float var12; float var12;
float var13; float var13;
@ -110,7 +111,7 @@
Block var15 = Block.blocksList[par3]; Block var15 = Block.blocksList[par3];
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float)(par6 - 2), (float)(par7 + 3), -3.0F + this.zLevel); GL11.glTranslatef((float)(par6 - 2), (float)(par7 + 3), -3.0F + this.zLevel);
@@ -221,7 +275,7 @@ @@ -221,7 +276,7 @@
if (Item.itemsList[par3].func_46058_c()) if (Item.itemsList[par3].func_46058_c())
{ {
GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_LIGHTING);
@ -119,7 +120,7 @@
for (var8 = 0; var8 <= 1; ++var8) for (var8 = 0; var8 <= 1; ++var8)
{ {
@@ -247,11 +301,11 @@ @@ -247,11 +302,11 @@
if (par3 < 256) if (par3 < 256)
{ {
@ -133,16 +134,16 @@
} }
var8 = Item.itemsList[par3].getColorFromDamage(par4, 0); var8 = Item.itemsList[par3].getColorFromDamage(par4, 0);
@@ -279,7 +333,58 @@ @@ -279,7 +334,58 @@
{ {
if (par3ItemStack != null) if (par3ItemStack != null)
{ {
- this.drawItemIntoGui(par1FontRenderer, par2RenderEngine, par3ItemStack.itemID, par3ItemStack.getItemDamage(), par3ItemStack.getIconIndex(), par4, par5); - this.drawItemIntoGui(par1FontRenderer, par2RenderEngine, par3ItemStack.itemID, par3ItemStack.getItemDamage(), par3ItemStack.getIconIndex(), par4, par5);
+ IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par3ItemStack, ItemRenderType.INVENTORY); + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par3ItemStack, INVENTORY);
+ if (customRenderer != null) + if (customRenderer != null)
+ { + {
+ par2RenderEngine.bindTexture(par2RenderEngine.getTexture(ForgeHooksClient.getTexture(par3ItemStack.itemID < 256 ? "/terrain.png" : "/gui/items.png", Item.itemsList[par3ItemStack.itemID]))); + par2RenderEngine.bindTexture(par2RenderEngine.getTexture(ForgeHooksClient.getTexture(par3ItemStack.itemID < 256 ? "/terrain.png" : "/gui/items.png", Item.itemsList[par3ItemStack.itemID])));
+ if (customRenderer.renderInventoryItemAsBlock(par3ItemStack)) + if (customRenderer.shouldUseRenderHelper(INVENTORY, par3ItemStack, INVENTORY_BLOCK))
+ { + {
+ GL11.glPushMatrix(); + GL11.glPushMatrix();
+ GL11.glTranslatef((float)(par4 - 2), (float)(par5 + 3), -3.0F + this.zLevel); + GL11.glTranslatef((float)(par4 - 2), (float)(par5 + 3), -3.0F + this.zLevel);
@ -161,7 +162,7 @@
+ } + }
+ GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);
+ renderBlocks.useInventoryTint = field_27004_a; + renderBlocks.useInventoryTint = field_27004_a;
+ ForgeHooksClient.renderInventoryItem(customRenderer, renderBlocks, par3ItemStack); + customRenderer.renderItem(INVENTORY, par3ItemStack, renderBlocks);
+ renderBlocks.useInventoryTint = true; + renderBlocks.useInventoryTint = true;
+ GL11.glPopMatrix(); + GL11.glPopMatrix();
+ } + }
@ -181,7 +182,7 @@
+ GL11.glColor4f(r, g, b, 1.0F); + GL11.glColor4f(r, g, b, 1.0F);
+ } + }
+ +
+ ForgeHooksClient.renderInventoryItem(customRenderer, renderBlocks, par3ItemStack); + customRenderer.renderItem(INVENTORY, par3ItemStack, renderBlocks);
+ GL11.glPopMatrix(); + GL11.glPopMatrix();
+ GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_LIGHTING);
+ } + }