Advertisement
WackoMcGoose

Render Dat Grass

Feb 7th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.34 KB | None | 0 0
  1. //BlockGrass.java
  2. package net.minecraft.src;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Random;
  6.  
  7. public class BlockGrass extends Block
  8. {
  9.     protected BlockGrass(int i)
  10.     {
  11.         super(i, Material.grass);
  12.         blockIndexInTexture = 3;
  13.         setTickOnLoad(true);
  14.     }
  15.  
  16.     public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
  17.     {
  18.         return super.getCollisionBoundingBoxFromPool(world, i, j, k);
  19.     }
  20.  
  21.     /*public void getCollidingBoundingBoxes(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, ArrayList arraylist)
  22.     {
  23.         setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.0625F, 0.875F);
  24.         super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
  25.         setBlockBounds(0.125F, 0.0625F, 0.125F, 0.875F, 0.875F, 0.1875F);
  26.         super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
  27.         setBlockBounds(0.125F, 0.0625F, 0.8125F, 0.875F, 0.875F, 0.875F);
  28.         super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
  29.         setBlockBounds(0.125F, 0.0625F, 0.1875F, 0.1875F, 0.875F, 0.8125F);
  30.         super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
  31.         setBlockBounds(0.8125F, 0.0625F, 0.1875F, 0.875F, 0.875F, 0.8125F);
  32.         super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
  33.         setBlockBoundsForItemRender();
  34.     }*/
  35.    
  36.     public void setBlockBoundsForItemRender() //Controls hitbox!
  37.     {
  38.         setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.875F, 1.0F);
  39.     }
  40.    
  41.     public int getBlockTextureFromSideAndMetadata(int i, int j)
  42.     {
  43.         if (i == 1)
  44.         {
  45.             return 0;
  46.         }
  47.         return i != 0 ? 3 : 2;
  48.     }
  49.  
  50.     public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
  51.     {
  52.         if (l == 1)
  53.         {
  54.             return 0;
  55.         }
  56.         if (l == 0)
  57.         {
  58.             return 2;
  59.         }
  60.         Material material = iblockaccess.getBlockMaterial(i, j + 1, k);
  61.         return material != Material.snow && material != Material.craftedSnow ? 3 : 68;
  62.     }
  63.  
  64.     public int getBlockColor()
  65.     {
  66.         double d = 0.5D;
  67.         double d1 = 1.0D;
  68.         return ColorizerGrass.getGrassColor(d, d1);
  69.     }
  70.  
  71.     public int getRenderColor(int i)
  72.     {
  73.         return getBlockColor();
  74.     }
  75.  
  76.     public int colorMultiplier(IBlockAccess iblockaccess, int i, int j, int k)
  77.     {
  78.         int l = 0;
  79.         int i1 = 0;
  80.         int j1 = 0;
  81.         for (int k1 = -1; k1 <= 1; k1++)
  82.         {
  83.             for (int l1 = -1; l1 <= 1; l1++)
  84.             {
  85.                 int i2 = iblockaccess.getWorldChunkManager().getBiomeGenAt(i + l1, k + k1).getGrassColorAtCoords(iblockaccess, i + l1, j, k + k1);
  86.                 l += (i2 & 0xff0000) >> 16;
  87.                 i1 += (i2 & 0xff00) >> 8;
  88.                 j1 += i2 & 0xff;
  89.             }
  90.         }
  91.  
  92.         return (l / 9 & 0xff) << 16 | (i1 / 9 & 0xff) << 8 | j1 / 9 & 0xff;
  93.     }
  94.  
  95.     public void updateTick(World world, int i, int j, int k, Random random)
  96.     {
  97.         if (world.multiplayerWorld)
  98.         {
  99.             return;
  100.         }
  101.         if (world.getBlockLightValue(i, j + 1, k) < 4 && Block.lightOpacity[world.getBlockId(i, j + 1, k)] > 2)
  102.         {
  103.             world.setBlockWithNotify(i, j, k, Block.dirt.blockID);
  104.         }
  105.         else if (world.getBlockLightValue(i, j + 1, k) >= 9)
  106.         {
  107.             for (int l = 0; l < 4; l++)
  108.             {
  109.                 int i1 = (i + random.nextInt(3)) - 1;
  110.                 int j1 = (j + random.nextInt(5)) - 3;
  111.                 int k1 = (k + random.nextInt(3)) - 1;
  112.                 int l1 = world.getBlockId(i1, j1 + 1, k1);
  113.                 if (world.getBlockId(i1, j1, k1) == Block.dirt.blockID && world.getBlockLightValue(i1, j1 + 1, k1) >= 4 && Block.lightOpacity[l1] <= 2 && l1 != Block.grass.blockID)
  114.                 {
  115.                     world.setBlockWithNotify(i1, j1, k1, Block.grass.blockID);
  116.                 }
  117.             }
  118.         }
  119.     }
  120.  
  121.     public int idDropped(int i, Random random, int j)
  122.     {
  123.         return Block.dirt.idDropped(0, random, j);
  124.     }
  125.    
  126.     public int getRenderType()
  127.     {
  128.         return mod_EvilMinecraft_Fragment.grassModelID;
  129.     }
  130.    
  131.     public boolean isOpaqueCube()
  132.     {
  133.         return false;
  134.     }
  135.    
  136.     public boolean renderAsNormalBlock()
  137.     {
  138.         return false;
  139.     }
  140. }
  141. //=========================================================================================================
  142. //mod_EvilMinecraft_Fragment.RenderGrassBlockInWorld(), controls render but not collision
  143.  
  144. private boolean RenderGrassBlockInWorld(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block)
  145.     {
  146.         int northBlockID = iblockaccess.getBlockId(i, j, k + 1);
  147.         if(northBlockID == 0) { northBlockID = 36; }
  148.         int eastBlockID = iblockaccess.getBlockId(i + 1, j, k);
  149.         if(eastBlockID == 0) { eastBlockID = 36; }
  150.         int southBlockID = iblockaccess.getBlockId(i, j, k - 1);
  151.         if(southBlockID == 0) { southBlockID = 36; }
  152.         int westBlockID = iblockaccess.getBlockId(i - 1, j, k);
  153.         if(westBlockID == 0) { westBlockID = 36; }
  154.         int northwestBlockID = iblockaccess.getBlockId(i - 1, j, k + 1);
  155.         if(northwestBlockID == 0) { northwestBlockID = 36; }
  156.         int northeastBlockID = iblockaccess.getBlockId(i + 1, j, k + 1);
  157.         if(northeastBlockID == 0) { northeastBlockID = 36; }
  158.         int southeastBlockID = iblockaccess.getBlockId(i + 1, j, k - 1);
  159.         if(southeastBlockID == 0) { southeastBlockID = 36; }
  160.         int southwestBlockID = iblockaccess.getBlockId(i - 1, j, k - 1);
  161.         if(southwestBlockID == 0) { southwestBlockID = 36; }
  162.         //System.out.println((new StringBuilder()).append("n=").append(northBlockID).append(" e=").append(eastBlockID).append(" s=").append(southBlockID).append(" w=").append(westBlockID).toString());
  163.         boolean blocksToNW = ((Block.blocksList[northBlockID].isOpaqueCube() || northBlockID == Block.grass.blockID) && (Block.blocksList[westBlockID].isOpaqueCube() || westBlockID == Block.grass.blockID) && (Block.blocksList[northwestBlockID].isOpaqueCube() || northwestBlockID == Block.grass.blockID));
  164.         boolean blocksToNE = ((Block.blocksList[northBlockID].isOpaqueCube() || northBlockID == Block.grass.blockID) && (Block.blocksList[eastBlockID].isOpaqueCube() || eastBlockID == Block.grass.blockID) && (Block.blocksList[northeastBlockID].isOpaqueCube() || northeastBlockID == Block.grass.blockID));
  165.         boolean blocksToSE = ((Block.blocksList[southBlockID].isOpaqueCube() || southBlockID == Block.grass.blockID) && (Block.blocksList[eastBlockID].isOpaqueCube() || eastBlockID == Block.grass.blockID) && (Block.blocksList[southeastBlockID].isOpaqueCube() || southeastBlockID == Block.grass.blockID));
  166.         boolean blocksToSW = ((Block.blocksList[southBlockID].isOpaqueCube() || southBlockID == Block.grass.blockID) && (Block.blocksList[westBlockID].isOpaqueCube() || westBlockID == Block.grass.blockID) && (Block.blocksList[southwestBlockID].isOpaqueCube() || southwestBlockID == Block.grass.blockID));
  167.         //Default case - Grass surrounded by solid blocks on all sides
  168.         if((Block.blocksList[northBlockID].isOpaqueCube()) && (Block.blocksList[eastBlockID].isOpaqueCube()) && (Block.blocksList[southBlockID].isOpaqueCube()) && (Block.blocksList[westBlockID].isOpaqueCube()))
  169.         {
  170.             block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  171.             renderblocks.renderStandardBlock(block, i, j, k);
  172.         }
  173.         else
  174.         {
  175.             //Base half-layer, placed even if grass has no solid blocks around it
  176.             block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
  177.             renderblocks.renderStandardBlock(block, i, j, k);
  178.             //Corner cases, NOT mutually exclusive (will usually have more than one!)
  179.             if(blocksToNW)
  180.             {
  181.                 block.setBlockBounds(0.0F, 0.5F, 0.5F, 0.5F, 1.0F, 1.0F);
  182.                 renderblocks.renderStandardBlock(block, i, j, k);
  183.             }
  184.             if(blocksToNE)
  185.             {
  186.                 block.setBlockBounds(0.5F, 0.5F, 0.5F, 1.0F, 1.0F, 1.0F);
  187.                 renderblocks.renderStandardBlock(block, i, j, k);
  188.             }
  189.             if(blocksToSE)
  190.             {
  191.                 block.setBlockBounds(0.5F, 0.5F, 0.0F, 1.0F, 1.0F, 0.5F);
  192.                 renderblocks.renderStandardBlock(block, i, j, k);
  193.             }
  194.             if(blocksToSW)
  195.             {
  196.                 block.setBlockBounds(0.0F, 0.5F, 0.0F, 0.5F, 1.0F, 0.5F);
  197.                 renderblocks.renderStandardBlock(block, i, j, k);
  198.             }
  199.         }
  200.         //Not rendered, just fix the stupid hitbox
  201.         block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  202.         return false;
  203.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement