Skip to content

Instantly share code, notes, and snippets.

@marchermans
Created June 7, 2015 12:40
Show Gist options
  • Save marchermans/fa2b47982a04441cc890 to your computer and use it in GitHub Desktop.
Save marchermans/fa2b47982a04441cc890 to your computer and use it in GitHub Desktop.
MutliLayerBlock
package com.Orion.Armory.World.Client.Render;
import com.Orion.Armory.Util.Client.CustomResource;
import com.Orion.Armory.World.Common.Block.BlockCommonMineable;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
/**
* Created by Marc on 6-6-2015.
*/
public class CommonMineableRenderHandler implements ISimpleBlockRenderingHandler {
public static final int ID = RenderingRegistry.getNextAvailableRenderId();
public void renderInventoryBlock(Block pBlock, int pMeta, int pId, RenderBlocks pRenderer) {
if (pId != ID)
return;
if (!(pBlock instanceof BlockCommonMineable))
return;
BlockCommonMineable tMineable = (BlockCommonMineable) pBlock;
for(int tRenderPass = 0; tRenderPass < tMineable.getRenderPassAmount(); tRenderPass++)
{
Tessellator tTess = Tessellator.instance;
CustomResource tResource = getResource(tMineable, pMeta, 0, tRenderPass);
GL11.glColor3f(tResource.getColor().getColorRedFloat(), tResource.getColor().getColorGreenFloat(), tResource.getColor().getColorBlueFloat());
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
tTess.startDrawingQuads();
tTess.setNormal(0.0F, -1F, 0.0F);
pRenderer.renderFaceYNeg(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
tTess.startDrawingQuads();
tTess.setNormal(0.0F, 1.0F, 0.0F);
pRenderer.renderFaceYPos(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
tTess.startDrawingQuads();
tTess.setNormal(0.0F, 0.0F, -1F);
pRenderer.renderFaceZNeg(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
tTess.startDrawingQuads();
tTess.setNormal(0.0F, 0.0F, 1.0F);
pRenderer.renderFaceZPos(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
tTess.startDrawingQuads();
tTess.setNormal(-1F, 0.0F, 0.0F);
pRenderer.renderFaceXNeg(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
tTess.startDrawingQuads();
tTess.setNormal(1.0F, 0.0F, 0.0F);
pRenderer.renderFaceXPos(pBlock, 0.0D, 0.0D, 0.0D, tResource.getIcon());
tTess.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
GL11.glColor3f(0F, 0F, 0F);
}
}
@Override
public boolean renderWorldBlock(IBlockAccess pWorld, int pX, int pY, int pZ, Block pBlock, int pId, RenderBlocks pRender) {
if (pId != ID)
return false;
if (!(pBlock instanceof BlockCommonMineable))
return false;
BlockCommonMineable tMineable = (BlockCommonMineable) pBlock;
for(int tRenderPass = 0; tRenderPass < tMineable.getRenderPassAmount(); tRenderPass++)
{
CustomResource tResource = getResource(tMineable, pWorld.getBlockMetadata(pX, pY, pZ), 0, tRenderPass);
pRender.setOverrideBlockTexture(tResource.getIcon());
renderBlock(pBlock, pX, pY, pZ, tResource, pRender);
pRender.clearOverrideBlockTexture();
}
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return true;
}
@Override
public int getRenderId() {
return ID;
}
public CustomResource getResource(BlockCommonMineable pBlock, int pMeta, int pSide, int pRenderPass)
{
CustomResource tResource = pBlock.getResource(pMeta, pSide, pRenderPass);
return tResource;
}
private boolean renderBlock(Block pBlock, int pX, int pY, int pZ, CustomResource pResource, RenderBlocks pRenderer) {
int l = pResource.getColor().getColor();
float f = (float) (l >> 16 & 255) / 255.0F;
float f1 = (float) (l >> 8 & 255) / 255.0F;
float f2 = (float) (l & 255) / 255.0F;
if (EntityRenderer.anaglyphEnable) {
float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F;
float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F;
float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F;
f = f3;
f1 = f4;
f2 = f5;
}
return Minecraft.isAmbientOcclusionEnabled() && pBlock.getLightValue() == 0 ? (pRenderer.partialRenderBounds ? pRenderer.renderStandardBlockWithAmbientOcclusionPartial(pBlock, pX, pY, pZ, f, f1, f2) : pRenderer.renderStandardBlockWithAmbientOcclusion(pBlock, pX, pY, pZ, f, f1, f2)) : pRenderer.renderStandardBlockWithColorMultiplier(pBlock, pX, pY, pZ, f, f1, f2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment