tterrag1098

Untitled

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