Merge branch 'GenuineSounds-patch-2' - fix the renderer for bad GL implementations
This commit is contained in:
commit
887ac8a216
|
@ -6,11 +6,11 @@
|
|||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest.client;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_COMPILE;
|
||||
import static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE;
|
||||
import static org.lwjgl.opengl.GL11.glColor4f;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
|
@ -45,11 +45,14 @@ import cpw.mods.ironchest.TileEntityIronChest;
|
|||
|
||||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
||||
private static Map<ItemStack, Integer> renderList = new HashMap<ItemStack, Integer>();
|
||||
|
||||
private Random random;
|
||||
|
||||
private RenderBlocks renderBlocks;
|
||||
|
||||
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F },
|
||||
{ 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
|
||||
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
|
||||
|
||||
public static boolean CACHE_RENDER = true;
|
||||
|
||||
public TileEntityIronChestRenderer() {
|
||||
model = new ModelChest();
|
||||
|
@ -58,19 +61,18 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
}
|
||||
|
||||
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
|
||||
if (tile==null) {
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
int facing = 3;
|
||||
IronChestType type=tile.getType();
|
||||
IronChestType type = tile.getType();
|
||||
if (tile != null && tile.worldObj != null) {
|
||||
facing = tile.getFacing();
|
||||
type=tile.getType();
|
||||
int typ=tile.worldObj.getBlockMetadata(tile.xCoord,tile.yCoord,tile.zCoord);
|
||||
type=IronChestType.values()[typ];
|
||||
type = tile.getType();
|
||||
int typ = tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
type = IronChestType.values()[typ];
|
||||
}
|
||||
bindTextureByName(type.getModelTexture());
|
||||
|
||||
glPushMatrix();
|
||||
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
@ -101,7 +103,6 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glPopMatrix();
|
||||
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
if (type.isTransparent()) {
|
||||
random.setSeed(254L);
|
||||
float shiftX;
|
||||
|
@ -120,7 +121,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
glDisable(2896 /* GL_LIGHTING */);
|
||||
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
||||
glTranslatef((float) x, (float) y, (float) z);
|
||||
EntityItem customitem=new EntityItem(tileEntityRenderer.worldObj);
|
||||
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
|
||||
for (ItemStack item : tile.getTopItemStacks()) {
|
||||
if (shift > shifts.length) {
|
||||
break;
|
||||
|
@ -133,9 +134,9 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
shiftY = shifts[shift][1];
|
||||
shiftZ = shifts[shift][2];
|
||||
shift++;
|
||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item,IItemRenderer.ItemRenderType.ENTITY);
|
||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
|
||||
float localScale = blockScale;
|
||||
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null) {
|
||||
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null) {
|
||||
int j = Block.blocksList[item.itemID].getRenderType();
|
||||
if (j == 1 || j == 19 || j == 12 || j == 2) {
|
||||
localScale = 2 * blockScale;
|
||||
|
@ -153,23 +154,24 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
|
||||
glTranslatef(minishiftX, minishiftY, minishiftZ);
|
||||
}
|
||||
|
||||
if (renderList.get(item) == null) {
|
||||
int render = glGenLists(1);
|
||||
renderList.put(item, render);
|
||||
glNewList(render, GL_COMPILE);
|
||||
if (renderList.get(item) == null || !CACHE_RENDER) { // Added support for using only old system.
|
||||
if (CACHE_RENDER) {
|
||||
int render = glGenLists(1);
|
||||
renderList.put(item, render);
|
||||
glNewList(render, GL_COMPILE_AND_EXECUTE);
|
||||
}
|
||||
if (customRenderer != null) {
|
||||
customitem.item=item;
|
||||
customitem.item = item;
|
||||
bindTextureByName("/terrain.png");
|
||||
ForgeHooksClient.overrideTexture(item.getItem());
|
||||
customRenderer.renderItem(IItemRenderer.ItemRenderType.ENTITY, item, renderBlocks, customitem);
|
||||
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
|
||||
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
|
||||
bindTextureByName("/terrain.png");
|
||||
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
|
||||
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
|
||||
} else {
|
||||
int i = item.getIconIndex();
|
||||
if (item.itemID >= Block.blocksList.length || Block.blocksList[item.itemID]==null) {
|
||||
if (item.itemID >= Block.blocksList.length || Block.blocksList[item.itemID] == null) {
|
||||
bindTextureByName("/gui/items.png");
|
||||
ForgeHooksClient.overrideTexture(Item.itemsList[item.itemID]);
|
||||
} else {
|
||||
|
@ -200,10 +202,13 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
|||
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
|
||||
tessellator.draw();
|
||||
}
|
||||
if (CACHE_RENDER)
|
||||
glEndList();
|
||||
} else {
|
||||
glCallList(renderList.get(item));
|
||||
Integer integer = renderList.get(item);
|
||||
if (integer != null) // Added null check for auto-unboxing JUST in case.
|
||||
glCallList(integer.intValue());
|
||||
}
|
||||
glEndList();
|
||||
glPopMatrix();
|
||||
}
|
||||
glPopMatrix();
|
||||
|
|
Loading…
Reference in New Issue