package zmaster587.advancedRocketry.client.render.multiblocks;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import zmaster587.libVulpes.block.RotatableBlock;
import zmaster587.libVulpes.tile.multiblock.TileMultiblockMachine;
public class RendererGenericMachineModel extends TileEntitySpecialRenderer {
IModelCustom model;
ResourceLocation texture;
public RendererGenericMachineModel(String modelPath, String texturePath) {
texture = new ResourceLocation(texturePath);
model = AdvancedModelLoader.loadModel(new ResourceLocation(modelPath));
}
@Override
public void renderTileEntityAt(TileEntity tile, double x,
double y, double z, float f) {
TileMultiblockMachine multiBlockTile = (TileMultiblockMachine)tile;
if(!multiBlockTile.canRender())
return;
GL11.glPushMatrix();
//Initial setup
int bright = tile.getWorldObj().getLightBrightnessForSkyBlocks(tile.xCoord, tile.yCoord + 1, tile.zCoord,0);
int brightX = bright % 65536;
int brightY = bright / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);
//Rotate and move the model into position
GL11.glTranslated(x+.5f, y, z + 0.5f);
ForgeDirection front = RotatableBlock.getFront(tile.getBlockMetadata());
GL11.glRotatef((front.offsetX == 1 ? 180 : 0) + front.offsetZ*90f, 0, 1, 0);
GL11.glTranslated(.5f, 0, 0f);
bindTexture(texture);
model.renderAll();
GL11.glPopMatrix();
}
}