Hey all, I've got an issue with a custom tile entity special renderer that I searched long and hard for a solution for, but wasn't able to find.
The tile entity is suppose to be a completely transparent, collision-free block that renders a highly animated magic circle at its location. The animation would have had an enormous number of frames if I had just done it as a texture with an mcmeta file, so I decided to split it into sections and have the tessellator handle the rotation animations for me.
[spoiler=textures (warning, large)]
One section rotates clockwise, while the other rotates counter-clockwise. They share a common center point, with a slight y-offset to prevent z-fighting.
Now... my problem is this. When placed in an open space, the entity functions perfectly. However, when placed near other, opaque blocks... well...
The textures are rendered around the middle of the block level that the tile entity is on, so I know that they're supposed to be showing over the blocks below them, and the same issue happens when I reverse the setup and stick the tile entity below a level of blocks. For some reason, the blocks are being rendered on top of my texture, despite being below it. Furthermore, the effect is inconsistent... If I move within a block or so y-distance to the tile entity, the problem goes away (at least, until I move again).
[spoiler=Here's my render code:]
package narhiril.homblocks.client;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import narhiril.homblocks.common.HomBlocks;
import narhiril.homblocks.common.blocks.BlockAthiCircle;
import narhiril.homblocks.common.tileentity.TileEntityAthiCircle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
public class TileEntityCircleRenderer extends TileEntitySpecialRenderer{
private float rotationAngle = 0.01F;
private float holdRotationAngle = 0.01F;
private static double minu = 0.0D;
private static double minv = 0.0D;
private static double maxu = 1.0D;
private static double maxv = 1.0D;
private static final ResourceLocation rl1 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleInner.png");
private static final ResourceLocation rl2 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleOuter.png");
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
Minecraft.getMinecraft().renderEngine.bindTexture(rl1);
x-= 0.5D;
z-= 0.5D;
float size = 5.0F; // in blocks
float height = 0.7F; // in blocks
double cx = x;
double cz = z;
double tempX = 0D;
double tempZ = 0D;
double rotatedX = 0D;
double rotatedZ = 0D;
double cornerX = x;
double cornerZ = z;
rotationAngle = rotationAngle + 0.01F;
if (rotationAngle >= 360.0F)
{
rotationAngle = 0.0F;
}
holdRotationAngle = rotationAngle;
double sinRot = Math.sin(rotationAngle);
double cosRot = Math.cos(rotationAngle);
Tessellator tessellator = Tessellator.instance;
GL11.glPushMatrix();
GL11.glTranslated(x+(size/2)-0.5, y+0.1, z+(size/2)-0.5);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
//first ring
tessellator.startDrawingQuads();
//rotation for corner 1
cornerX = x-size;
cornerZ = z-size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);
//rotation for corner 2
cornerX = x-size;
cornerZ = z+size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
//rotation for corner 3
cornerX = x+size;
cornerZ = z+size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);
//rotation for corner 4
cornerX = x+size;
cornerZ = z-size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);
tessellator.draw();
//second ring
rotationAngle = 360-rotationAngle; //retrograde spin
Minecraft.getMinecraft().renderEngine.bindTexture(rl2);
sinRot = Math.sin(rotationAngle);
cosRot = Math.cos(rotationAngle);
size = 5.0F;
height = 0.6F;
tessellator.startDrawingQuads();
//rotation for corner 1
cornerX = x-size;
cornerZ = z-size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);
//rotation for corner 2
cornerX = x-size;
cornerZ = z+size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
//rotation for corner 3
cornerX = x+size;
cornerZ = z+size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);
//rotation for corner 4
cornerX = x+size;
cornerZ = z-size;
tempX = cornerX - cx;
tempZ = cornerZ - cz;
rotatedX = tempX*cosRot - tempZ*sinRot;
rotatedZ = tempX*sinRot + tempZ*cosRot;
cornerX = rotatedX + cx;
cornerZ = rotatedZ + cz;
tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);
tessellator.draw();
rotationAngle = holdRotationAngle;
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
}
I was under the impression that tile entities were rendered last, after both block render passes. So... why is this happening, and what can I do to fix it?
Thanks a bunch in advance.