2011-07-15 23:13:09 +00:00
|
|
|
/**
|
2012-02-25 06:07:58 +00:00
|
|
|
* This software is provided under the terms of the Minecraft Forge Public
|
2011-07-15 23:13:09 +00:00
|
|
|
* License v1.0.
|
|
|
|
*/
|
|
|
|
|
2012-08-06 22:07:53 +00:00
|
|
|
package net.minecraftforge.client;
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2013-05-16 00:29:47 +00:00
|
|
|
import java.util.BitSet;
|
2013-12-21 08:10:35 +00:00
|
|
|
import java.util.IdentityHashMap;
|
2013-05-16 00:29:47 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2012-08-06 22:07:53 +00:00
|
|
|
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
2011-07-15 23:04:10 +00:00
|
|
|
|
2012-02-25 06:07:58 +00:00
|
|
|
public class MinecraftForgeClient
|
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
private static IdentityHashMap<Item, IItemRenderer> customItemRenderers = Maps.newIdentityHashMap();
|
2012-03-17 18:46:15 +00:00
|
|
|
|
2012-09-09 14:02:21 +00:00
|
|
|
/**
|
2012-08-06 22:07:53 +00:00
|
|
|
* Register a custom renderer for a specific item. This can be used to
|
2012-03-17 18:46:15 +00:00
|
|
|
* render the item in-world as an EntityItem, when the item is equipped, or
|
|
|
|
* when the item is in an inventory slot.
|
|
|
|
* @param itemID The item ID (shifted index) to handle rendering.
|
|
|
|
* @param renderer The IItemRenderer interface that handles rendering for
|
|
|
|
* this item.
|
2012-03-16 04:26:09 +00:00
|
|
|
*/
|
2013-12-21 08:10:35 +00:00
|
|
|
public static void registerItemRenderer(Item item, IItemRenderer renderer)
|
2012-03-16 04:26:09 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
customItemRenderers.put(item, renderer);
|
2012-03-16 04:26:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 18:37:51 +00:00
|
|
|
public static IItemRenderer getItemRenderer(ItemStack item, ItemRenderType type)
|
2012-03-16 04:26:09 +00:00
|
|
|
{
|
2014-01-06 04:55:04 +00:00
|
|
|
IItemRenderer renderer = customItemRenderers.get(item.getItem());
|
2012-09-09 14:02:21 +00:00
|
|
|
if (renderer != null && renderer.handleRenderType(item, type))
|
2012-03-23 02:46:36 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
return renderer;
|
2012-03-17 18:46:15 +00:00
|
|
|
}
|
|
|
|
return null;
|
2012-02-25 06:07:58 +00:00
|
|
|
}
|
2013-03-07 03:18:26 +00:00
|
|
|
|
2013-03-07 03:26:29 +00:00
|
|
|
public static int getRenderPass()
|
2013-03-07 03:18:26 +00:00
|
|
|
{
|
|
|
|
return ForgeHooksClient.renderPass;
|
|
|
|
}
|
2013-05-09 00:13:19 +00:00
|
|
|
|
2013-05-11 14:58:02 +00:00
|
|
|
public static int getStencilBits()
|
2013-05-09 00:13:19 +00:00
|
|
|
{
|
|
|
|
return ForgeHooksClient.stencilBits;
|
|
|
|
}
|
2013-05-16 00:29:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
private static BitSet stencilBits = new BitSet(getStencilBits());
|
|
|
|
static
|
|
|
|
{
|
|
|
|
stencilBits.set(0,getStencilBits());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserve a stencil bit for use in rendering
|
|
|
|
*
|
|
|
|
* @return A bit or -1 if no further stencil bits are available
|
|
|
|
*/
|
|
|
|
public static int reserveStencilBit()
|
|
|
|
{
|
|
|
|
int bit = stencilBits.nextSetBit(0);
|
|
|
|
if (bit >= 0)
|
|
|
|
{
|
|
|
|
stencilBits.clear(bit);
|
|
|
|
}
|
|
|
|
return bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release the stencil bit for other use
|
|
|
|
*
|
|
|
|
* @param bit The bit from {@link #reserveStencilBit()}
|
|
|
|
*/
|
|
|
|
public static void releaseStencilBit(int bit)
|
|
|
|
{
|
|
|
|
if (bit >= 0 && bit < getStencilBits())
|
|
|
|
{
|
|
|
|
stencilBits.set(bit);
|
|
|
|
}
|
|
|
|
}
|
2011-07-15 23:04:10 +00:00
|
|
|
}
|