tterrag1098

Untitled

Nov 18th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.46 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,
  38.             int z, Block rawBlock, int modelId, RenderBlocks renderer) {
  39.         if (modelId == getRenderId()) {
  40.             System.out.println(blockAccess.getBlockId(x, y, z));
  41.             int id = blockAccess.getBlockId(x, y, z);
  42.             int brightness = rawBlock.getMixedBrightnessForBlock(blockAccess,
  43.                     x, y, z);
  44.  
  45.             Tessellator tessellator = Tessellator.instance;
  46.             tessellator.setColorOpaque_I(((BlockLamp)rawBlock).getBlockColor(blockAccess.getBlockMetadata(x, y, z)));
  47.             tessellator.setBrightness(brightness);
  48.            
  49.             BlockLamp block = ((BlockLamp) rawBlock);
  50.  
  51.             renderer.renderFaceYNeg(block, x, y, z, BlockLamp.icons[12]);
  52.             renderer.renderFaceYPos(block, x, y, z, BlockLamp.icons[12]);
  53.             renderer.renderFaceXNeg(block, x, y, z, BlockLamp.icons[12]);
  54.             renderer.renderFaceXPos(block, x, y, z, BlockLamp.icons[12]);
  55.             renderer.renderFaceZNeg(block, x, y, z, BlockLamp.icons[12]);
  56.             renderer.renderFaceZPos(block, x, y, z, BlockLamp.icons[12]);
  57.  
  58.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 0))
  59.                 if (icon != null)
  60.                     renderer.renderFaceYNeg(block, x, y, z, icon);
  61.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 1))
  62.                 if (icon != null)
  63.                     renderer.renderFaceYPos(block, x, y, z, icon);
  64.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 2))
  65.                 if (icon != null)
  66.                     renderer.renderFaceXNeg(block, x, y, z, icon);
  67.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 3))
  68.                 if (icon != null)
  69.                     renderer.renderFaceXPos(block, x, y, z, icon);
  70.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 4))
  71.                 if (icon != null)
  72.                     renderer.renderFaceZNeg(block, x, y, z, icon);
  73.             for (Icon icon : getIconsToDraw(blockAccess, x, y, z, block, 5))
  74.                 if (icon != null)
  75.                     renderer.renderFaceZPos(block, x, y, z, icon);
  76.            
  77.             block.getRenderColor(0);
  78.             }
  79.         return true;
  80.     }
  81.  
  82.       private Icon[] getIcons()
  83.       {
  84.           Icon[] allIcons = BlockLamp.icons;
  85.           Icon[] newIcons = new Icon[12];
  86.           for (int i = 0; i < 12; i++)
  87.               newIcons[i] = allIcons[i];
  88.           return newIcons;
  89.       }
  90.      
  91.       public Icon[] getIconsToDraw(IBlockAccess blockAccess, int x, int y, int z, Block block, int side)
  92.       {
  93.           boolean up = false, down = false, left = false, right = false, upLeft = false, upRight = false, downLeft = false, downRight = false;
  94.           int id = block.blockID;
  95.  
  96.         Icon[] iconsToDraw = new Icon[12];
  97.         int index = 0;
  98.        
  99.         Icon[] allIcons = getIcons();
  100.        
  101.         switch (side) {
  102.         case 0:
  103.             up = id == blockAccess.getBlockId(x, y, z - 1);
  104.             down = id == blockAccess.getBlockId(x, y, z + 1);
  105.             left = id == blockAccess.getBlockId(x - 1, y, z);
  106.             right = id == blockAccess.getBlockId(x + 1, y, z);
  107.             upLeft = id == blockAccess.getBlockId(x - 1, y, z - 1);
  108.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  109.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  110.             downRight = id == blockAccess.getBlockId(x + 1, y, z + 1);
  111.             break;
  112.         case 1:
  113.             up = id == blockAccess.getBlockId(x, y, z - 1);
  114.             down = id == blockAccess.getBlockId(x, y, z + 1);
  115.             left = id == blockAccess.getBlockId(x - 1, y, z);
  116.             right = id == blockAccess.getBlockId(x + 1, y, z);
  117.             upLeft = id == blockAccess.getBlockId(x - 1, y, z - 1);
  118.             upRight = id == blockAccess.getBlockId(x + 1, y, z - 1);
  119.             downLeft = id == blockAccess.getBlockId(x - 1, y, z + 1);
  120.             downRight = id == blockAccess.getBlockId(x + 1, y, z + 1);
  121.             break;
  122.         case 2:
  123.             up = id == blockAccess.getBlockId(x, y + 1, z);
  124.             down = id == blockAccess.getBlockId(x, y - 1, z);
  125.             left = id == blockAccess.getBlockId(x, y, z - 1);
  126.             right = id == blockAccess.getBlockId(x, y, z + 1);
  127.             upLeft = id == blockAccess.getBlockId(x, y + 1, z - 1);
  128.             upRight = id == blockAccess.getBlockId(x, y + 1, z + 1);
  129.             downLeft = id == blockAccess.getBlockId(x, y - 1, z - 1);
  130.             downRight = id == blockAccess.getBlockId(x, y - 1, z + 1);
  131.             break;
  132.         case 3:
  133.             up = id == blockAccess.getBlockId(x, y + 1, z);
  134.             down = id == blockAccess.getBlockId(x, y - 1, z);
  135.             left = id == blockAccess.getBlockId(x, y, z + 1);
  136.             right = id == blockAccess.getBlockId(x, y, z - 1);
  137.             upLeft = id == blockAccess.getBlockId(x, y + 1, z + 1);
  138.             upRight = id == blockAccess.getBlockId(x, y + 1, z - 1);
  139.             downLeft = id == blockAccess.getBlockId(x, y - 1, z + 1);
  140.             downRight = id == blockAccess.getBlockId(x, y - 1, z - 1);
  141.             break;
  142.         case 4:
  143.             up = id == blockAccess.getBlockId(x, y + 1, z);
  144.             down = id == blockAccess.getBlockId(x, y - 1, z);
  145.             left = id == blockAccess.getBlockId(x + 1, y, z);
  146.             right = id == blockAccess.getBlockId(x - 1, y, z);
  147.             upLeft = id == blockAccess.getBlockId(x + 1, y + 1, z);
  148.             upRight = id == blockAccess.getBlockId(x - 1, y + 1, z);
  149.             downLeft = id == blockAccess.getBlockId(x + 1, y - 1, z);
  150.             downRight = id == blockAccess.getBlockId(x - 1, y - 1, z);
  151.             break;
  152.         case 5:
  153.             up = id == blockAccess.getBlockId(x, y + 1, z);
  154.             down = id == blockAccess.getBlockId(x, y - 1, z);
  155.             left = id == blockAccess.getBlockId(x - 1, y, z);
  156.             right = id == blockAccess.getBlockId(x + 1, y, z);
  157.             upLeft = id == blockAccess.getBlockId(x - 1, y + 1, z);
  158.             upRight = id == blockAccess.getBlockId(x + 1, y + 1, z);
  159.             downLeft = id == blockAccess.getBlockId(x - 1, y - 1, z);
  160.             downRight = id == blockAccess.getBlockId(x + 1, y - 1, z);
  161.             break;
  162.         }
  163.         if (!up)
  164.         {
  165.             iconsToDraw[index] = allIcons[0];
  166.             index++;
  167.         }
  168.         if (!right)
  169.         {
  170.             iconsToDraw[index] = allIcons[1];
  171.             index++;
  172.         }
  173.         if (!down)
  174.         {
  175.             iconsToDraw[index] = allIcons[2];
  176.             index++;
  177.         }
  178.         if (!left)
  179.         {
  180.             iconsToDraw[index] = allIcons[3];
  181.             index++;
  182.         }
  183.         if (!upLeft && (up && left))
  184.         {
  185.             iconsToDraw[index] = allIcons[4];
  186.             index++;
  187.         }
  188.         if (!downLeft && (down && left))
  189.         {
  190.             iconsToDraw[index] = allIcons[5];
  191.             index++;
  192.         }
  193.         if (!downRight && (down && right))
  194.         {
  195.             iconsToDraw[index] = allIcons[6];
  196.             index++;
  197.         }
  198.         if (!upRight && (up && right))
  199.         {
  200.             iconsToDraw[index] = allIcons[7];
  201.             index++;
  202.         }
  203.         if (!up && !left)
  204.         {
  205.             iconsToDraw[index] = allIcons[8];
  206.             index++;
  207.         }
  208.         if (!down && !left)
  209.         {
  210.             iconsToDraw[index] = allIcons[9];
  211.             index++;
  212.         }
  213.         if (!down && !right)
  214.         {
  215.             iconsToDraw[index] = allIcons[10];
  216.             index++;
  217.         }
  218.         if (!up && !right)
  219.         {
  220.             iconsToDraw[index] = allIcons[11];
  221.             index++;
  222.         }
  223.         return iconsToDraw;
  224.       }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment