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