Advertisement
WackoMcGoose

BlockGrass changes

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