tterrag1098

Untitled

Nov 17th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.66 KB | None | 0 0
  1. package tterrag.stoneLamp.client;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.client.renderer.RenderBlocks;
  5. import net.minecraft.client.renderer.Tessellator;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.util.Icon;
  8. import net.minecraft.world.IBlockAccess;
  9. import tterrag.stoneLamp.block.BlockLamp;
  10. import tterrag.stoneLamp.block.ModBlock;
  11. import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
  12.  
  13. public class ColoredLampRenderer implements ISimpleBlockRenderingHandler {
  14.  
  15.     static int renderPass;
  16.  
  17.       @Override
  18.       public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
  19.         renderer.setOverrideBlockTexture(BlockLamp.icons[0]);
  20.         renderer.renderBlockAsItem(Block.glass, 0, 1);
  21.         renderer.clearOverrideBlockTexture();
  22.       }
  23.  
  24.       @Override
  25.       public boolean shouldRender3DInInventory() {
  26.         return true;
  27.       }
  28.  
  29.       @Override
  30.       public int getRenderId() {
  31.         return BlockLamp.renderId;
  32.       }
  33.  
  34.       @Override
  35.       public boolean renderWorldBlock(IBlockAccess blockAccess, int x, int y, int z, Block rawBlock, int modelId, RenderBlocks renderer) {
  36.         if(renderPass == 0)
  37.         {
  38.           RenderUtil.setTesselatorBrightness(blockAccess, x, y, z);
  39.           System.out.println(blockAccess.getBlockId(x, y, z));
  40.           int id = blockAccess.getBlockId(x, y, z);
  41.           int brightness = rawBlock.getMixedBrightnessForBlock(blockAccess, x, y, z);
  42.          
  43.           if (rawBlock instanceof BlockLamp && id == ModBlock.LAMP_ID || id == ModBlock.EMPTYLAMP_ID || id == ModBlock.COLOREDLAMP_ID || id == ModBlock.EMPTYCOLOREDLAMP_ID)
  44.           {
  45.               BlockLamp block = ((BlockLamp) rawBlock);
  46.              
  47.               renderer.renderFaceYNeg(block, x, y, z, BlockLamp.icons[15]);
  48.               renderer.renderFaceYPos(block, x, y, z, BlockLamp.icons[15]);
  49.               renderer.renderFaceXNeg(block, x, y, z, BlockLamp.icons[15]);
  50.               renderer.renderFaceXPos(block, x, y, z, BlockLamp.icons[15]);
  51.               renderer.renderFaceZNeg(block, x, y, z, BlockLamp.icons[15]);
  52.               renderer.renderFaceZPos(block, x, y, z, BlockLamp.icons[15]);
  53.              
  54.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 0))
  55.                     if (icon != null)
  56.                         renderer.renderFaceYNeg(block, x, y, z, icon);
  57.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 1))
  58.                     if (icon != null)
  59.                         renderer.renderFaceYPos(block, x, y, z, icon);
  60.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 2))
  61.                     if (icon != null)
  62.                         renderer.renderFaceXNeg(block, x, y, z, icon);
  63.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 3))
  64.                     if (icon != null)
  65.                         renderer.renderFaceXPos(block, x, y, z, icon);
  66.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 4))
  67.                     if (icon != null)
  68.                         renderer.renderFaceZNeg(block, x, y, z, icon);
  69.                 for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 5))
  70.                     if (icon != null)
  71.                         renderer.renderFaceZPos(block, x, y, z, icon);
  72.              
  73.               //renderer.renderStandardBlock(block, x, y, z);
  74.           }
  75.           else
  76.           {
  77.               renderer.setOverrideBlockTexture(BlockLamp.icons[0]);
  78.               renderer.renderStandardBlock(rawBlock, x, y, z);
  79.               renderer.clearOverrideBlockTexture();
  80.           }
  81.          
  82.         }
  83.         Tessellator tessellator = Tessellator.instance;
  84.         tessellator.setBrightness(rawBlock.getMixedBrightnessForBlock(blockAccess, x, y, z));
  85.          
  86.         return true;
  87.      }
  88.  
  89.       public void renderFrameItem(ItemStack stack) {
  90.         RenderUtil.bindBlockTexture();
  91.         Tessellator.instance.draw();
  92.       }
  93.      
  94.       public Icon[] getIconsToDraw(IBlockAccess blockAccess, int x, int y, int z, Block block, int side)
  95.       {
  96.           boolean up, down, left, right, upLeft, upRight, downLeft, downRight;
  97.           int id = block.blockID;
  98.  
  99.         switch (side) {
  100.         case 0:
  101.             up = id == blockAccess.getBlockId(x + 1, y, z);
  102.             down = id == blockAccess.getBlockId(x - 1, y, z);
  103.             left = id == blockAccess.getBlockId(x, y, z + 1);
  104.             right = id == blockAccess.getBlockId(x, y, z - 1);
  105.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  106.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  107.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  108.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  109.             break;
  110.         case 1:
  111.             up = id == blockAccess.getBlockId(x + 1, y, z);
  112.             down = id == blockAccess.getBlockId(x - 1, y, z);
  113.             left = id == blockAccess.getBlockId(x, y, z + 1);
  114.             right = id == blockAccess.getBlockId(x, y, z - 1);
  115.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  116.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  117.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  118.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  119.             break;
  120.         case 2:
  121.             up = id == blockAccess.getBlockId(x + 1, y, z);
  122.             down = id == blockAccess.getBlockId(x - 1, y, z);
  123.             left = id == blockAccess.getBlockId(x, y, z + 1);
  124.             right = id == blockAccess.getBlockId(x, y, z - 1);
  125.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  126.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  127.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  128.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  129.             break;
  130.         case 3:
  131.             up = id == blockAccess.getBlockId(x + 1, y, z);
  132.             down = id == blockAccess.getBlockId(x - 1, y, z);
  133.             left = id == blockAccess.getBlockId(x, y, z + 1);
  134.             right = id == blockAccess.getBlockId(x, y, z - 1);
  135.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  136.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  137.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  138.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  139.             break;
  140.         case 4:
  141.             up = id == blockAccess.getBlockId(x + 1, y, z);
  142.             down = id == blockAccess.getBlockId(x - 1, y, z);
  143.             left = id == blockAccess.getBlockId(x, y, z + 1);
  144.             right = id == blockAccess.getBlockId(x, y, z - 1);
  145.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  146.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  147.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  148.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  149.             break;
  150.         case 5:
  151.             up = id == blockAccess.getBlockId(x + 1, y, z);
  152.             down = id == blockAccess.getBlockId(x - 1, y, z);
  153.             left = id == blockAccess.getBlockId(x, y, z + 1);
  154.             right = id == blockAccess.getBlockId(x, y, z - 1);
  155.             upLeft = id == blockAccess.getBlockId(x + 1, y, z + 1);
  156.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  157.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  158.             downRight = id == blockAccess.getBlockId(x - 1, y, z + 1);
  159.             break;
  160.  
  161.           }
  162.        
  163.         return new Icon[1];
  164.          
  165.       }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment