Fixed how textures are handled on conveyor belt render to improve performance

This commit is contained in:
Robert S 2014-05-22 15:02:54 -04:00
parent 9d84de4761
commit 7bb06255e0

View file

@ -1,5 +1,7 @@
package resonantinduction.mechanical.belt; package resonantinduction.mechanical.belt;
import java.util.HashMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -17,128 +19,154 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class RenderConveyorBelt extends TileEntitySpecialRenderer implements ISimpleItemRenderer public class RenderConveyorBelt extends TileEntitySpecialRenderer implements ISimpleItemRenderer
{ {
public static final ModelConveyorBelt MODEL = new ModelConveyorBelt(); public static final ModelConveyorBelt MODEL = new ModelConveyorBelt();
public static final ModelAngledBelt MODEL2 = new ModelAngledBelt(); public static final ModelAngledBelt MODEL2 = new ModelAngledBelt();
public static HashMap<Integer, ResourceLocation> beltTextureFrames = new HashMap<Integer, ResourceLocation>();
public static HashMap<Integer, ResourceLocation> slantedBeltTextureFrames = new HashMap<Integer, ResourceLocation>();
@Override @Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{ {
TileConveyorBelt tileEntity = (TileConveyorBelt) t; final TileConveyorBelt beltTile = (TileConveyorBelt) t;
BeltType slantType = tileEntity.getBeltType(); final BeltType slantType = beltTile.getBeltType();
int face = tileEntity.getDirection().ordinal(); final int face = beltTile.getDirection().ordinal();
final int frame = beltTile.getAnimationFrame();
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glRotatef(180f, 0f, 0f, 1f); GL11.glRotatef(180f, 0f, 0f, 1f);
int frame = tileEntity.getAnimationFrame(); /* Assign texture */
bindTexture(getTexture(slantType == BeltType.SLANT_UP || slantType == BeltType.SLANT_DOWN, frame));
if (slantType != null && slantType != BeltType.NORMAL)
{
switch (face)
{
case 2:
GL11.glRotatef(180f, 0f, 1f, 0f);
break;
case 3:
GL11.glRotatef(0f, 0f, 1f, 0f);
break;
case 4:
GL11.glRotatef(90f, 0f, 1f, 0f);
break;
case 5:
GL11.glRotatef(-90f, 0f, 1f, 0f);
break;
}
if (slantType != null && slantType != BeltType.NORMAL) if (slantType == BeltType.SLANT_UP)
{ {
switch (face) GL11.glTranslatef(0f, 0.8f, -0.8f);
{ GL11.glRotatef(180f, 0f, 1f, 1f);
case 2: TileEntity test = beltTile.worldObj.getBlockTileEntity(beltTile.xCoord + beltTile.getDirection().offsetX, beltTile.yCoord, beltTile.zCoord + beltTile.getDirection().offsetZ);
GL11.glRotatef(180f, 0f, 1f, 0f); if (test != null)
break; {
case 3: if (test instanceof TileConveyorBelt)
GL11.glRotatef(0f, 0f, 1f, 0f); {
break; if (((TileConveyorBelt) test).getBeltType() == BeltType.RAISED)
case 4: {
GL11.glRotatef(90f, 0f, 1f, 0f); GL11.glRotatef(10f, 1f, 0f, 0f);
break; }
case 5: }
GL11.glRotatef(-90f, 0f, 1f, 0f); }
break; MODEL2.render(0.0625F, true);
} }
else if (slantType == BeltType.SLANT_DOWN)
{
boolean slantAdjust = false;
TileEntity test = beltTile.worldObj.getBlockTileEntity(beltTile.xCoord - beltTile.getDirection().offsetX, beltTile.yCoord, beltTile.zCoord - beltTile.getDirection().offsetZ);
if (test != null)
{
if (test instanceof TileConveyorBelt)
{
if (((TileConveyorBelt) test).getBeltType() == BeltType.RAISED)
{
GL11.glRotatef(-10f, 1f, 0f, 0f);
GL11.glTranslatef(0f, 0.25f, 0f);
slantAdjust = true;
}
}
}
MODEL2.render(0.0625F, slantAdjust);
}
else
{
GL11.glRotatef(180, 0f, 1f, 0f);
GL11.glTranslatef(0f, -0.68f, 0f);
MODEL.render(0.0625f, 0 /* TODO add rotation */, false, false, false, false);
}
}
else
{
switch (face)
{
case 2:
GL11.glRotatef(0f, 0f, 1f, 0f);
break;
case 3:
GL11.glRotatef(180f, 0f, 1f, 0f);
break;
case 4:
GL11.glRotatef(-90f, 0f, 1f, 0f);
break;
case 5:
GL11.glRotatef(90f, 0f, 1f, 0f);
break;
}
MODEL.render(0.0625F, 0 /* TODO add rotation */, false, false, false, true);
if (slantType == BeltType.SLANT_UP) }
{ GL11.glPopMatrix();
ResourceLocation name = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "slantedbelt/frame" + frame + ".png"); }
bindTexture(name);
GL11.glTranslatef(0f, 0.8f, -0.8f); /** Gets the texture for the belt at the given frame of animation
GL11.glRotatef(180f, 0f, 1f, 1f); *
boolean slantAdjust = false; * @param slant - is the belt slanted up or down
TileEntity test = tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord + tileEntity.getDirection().offsetX, tileEntity.yCoord, tileEntity.zCoord + tileEntity.getDirection().offsetZ); * @param frame - frame of animation
if (test != null) * @return ResourceLocation for the frame of animation */
{ public static ResourceLocation getTexture(boolean slant, int frame)
if (test instanceof TileConveyorBelt) {
{ ResourceLocation texture = null;
if (((TileConveyorBelt) test).getBeltType() == BeltType.RAISED) if (slant)
{ {
GL11.glRotatef(10f, 1f, 0f, 0f); /* Store slanted belt textures to make retrieving them faster */
slantAdjust = true; if (slantedBeltTextureFrames.containsKey(frame))
} {
} texture = slantedBeltTextureFrames.get(frame);
} }
MODEL2.render(0.0625F, true); if (texture == null)
} {
else if (slantType == BeltType.SLANT_DOWN) texture = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "slantedbelt/frame" + frame + ".png");
{ slantedBeltTextureFrames.put(frame, texture);
ResourceLocation name = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "slantedbelt/frame" + frame + ".png"); }
bindTexture(name); }
GL11.glRotatef(180f, 0f, 1f, 0f); else
boolean slantAdjust = false; {
TileEntity test = tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord - tileEntity.getDirection().offsetX, tileEntity.yCoord, tileEntity.zCoord - tileEntity.getDirection().offsetZ); /* Store belt textures to make retrieving them faster */
if (test != null) if (beltTextureFrames.containsKey(frame))
{ {
if (test instanceof TileConveyorBelt) texture = beltTextureFrames.get(frame);
{ }
if (((TileConveyorBelt) test).getBeltType() == BeltType.RAISED) if (texture == null)
{ {
GL11.glRotatef(-10f, 1f, 0f, 0f); texture = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "belt/frame" + frame + ".png");
GL11.glTranslatef(0f, 0.25f, 0f); beltTextureFrames.put(frame, texture);
slantAdjust = true; }
} }
} return texture;
} }
MODEL2.render(0.0625F, slantAdjust);
}
else
{
ResourceLocation name = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "belt/frame" + frame + ".png");
bindTexture(name);
GL11.glRotatef(180, 0f, 1f, 0f);
GL11.glTranslatef(0f, -0.68f, 0f);
MODEL.render(0.0625f, 0 /* TODO add rotation */, false, false, false, false);
}
}
else
{
switch (face)
{
case 2:
GL11.glRotatef(0f, 0f, 1f, 0f);
break;
case 3:
GL11.glRotatef(180f, 0f, 1f, 0f);
break;
case 4:
GL11.glRotatef(-90f, 0f, 1f, 0f);
break;
case 5:
GL11.glRotatef(90f, 0f, 1f, 0f);
break;
}
ResourceLocation name = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "belt/frame" + frame + ".png");
bindTexture(name);
MODEL.render(0.0625F, 0 /* TODO add rotation */, false, false, false, true);
} @Override
public void renderInventoryItem(ItemStack itemStack)
int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); {
GL11.glPushMatrix();
GL11.glPopMatrix(); GL11.glTranslatef(0.5f, 1.7F, 0.5f);
} GL11.glRotatef(180f, 0f, 0f, 1f);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(getTexture(false, 0));
@Override MODEL.render(0.0625F, 0, false, false, false, false);
public void renderInventoryItem(ItemStack itemStack) GL11.glPopMatrix();
{ }
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 1.7F, 0.5f);
GL11.glRotatef(180f, 0f, 0f, 1f);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "belt/frame0.png"));
MODEL.render(0.0625F, 0, false, false, false, false);
GL11.glPopMatrix();
}
} }