package blusunrize.immersiveengineering.client.render;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.TileEntityArcFurnace;
import com.google.common.collect.Lists;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.model.obj.OBJModel.OBJState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.Properties;
import org.lwjgl.opengl.GL11;
import java.util.List;
public class TileRenderArcFurnace extends TileEntitySpecialRenderer<TileEntityArcFurnace>
{
@Override
public void renderTileEntityAt(TileEntityArcFurnace te, double x, double y, double z, float partialTicks, int destroyStage)
{
if(!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
return;
List<String> renderedParts = null;
for(int i=0; i<3; i++)
if(te.getInventory()[23+i]!=null)
{
if(renderedParts==null)
renderedParts = Lists.newArrayList("electrode"+(i+1));
else
renderedParts.add("electrode"+(i+1));
}
if(renderedParts==null)
return;
if(te.shouldRenderAsActive())
renderedParts.add("active");
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos blockPos = te.getPos();
IBlockState state = getWorld().getBlockState(blockPos);
if(state.getBlock() != IEContent.blockMetalMultiblock)
return;
state = state.getBlock().getActualState(state, getWorld(), blockPos);
state = state.withProperty(IEProperties.DYNAMICRENDER, true);
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
if(state instanceof IExtendedBlockState)
state = ((IExtendedBlockState)state).withProperty(Properties.AnimationProperty, new OBJState(renderedParts, true));
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer worldRenderer = tessellator.getBuffer();
ClientUtils.bindAtlas();
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
GlStateManager.translate(.5, .5, .5);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
if(Minecraft.isAmbientOcclusionEnabled())
GlStateManager.shadeModel(7425);
else
GlStateManager.shadeModel(7424);
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
worldRenderer.setTranslation( -.5-blockPos.getX(), -.5- blockPos.getY(), -.5-blockPos.getZ());
worldRenderer.color(255, 255, 255, 255);
blockRenderer.getBlockModelRenderer().renderModel(te.getWorld(), model, state, blockPos, worldRenderer, true);
worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
tessellator.draw();
RenderHelper.enableStandardItemLighting();
GlStateManager.popMatrix();
}
}