Advertisement
Guest User

Generic Sapling Block Code

a guest
Sep 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.59 KB | None | 0 0
  1. package net.mod.adamDoesMods.Biomes.features;
  2.  
  3. import java.util.List;
  4.  
  5. import java.util.Random;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockSapling;
  9. import net.minecraft.client.renderer.texture.IIconRegister;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.IIcon;
  15. import net.minecraft.util.MathHelper;
  16. import net.minecraft.world.World;
  17. import net.minecraft.world.gen.feature.WorldGenBigTree;
  18. import net.minecraft.world.gen.feature.WorldGenCanopyTree;
  19. import net.minecraft.world.gen.feature.WorldGenForest;
  20. import net.minecraft.world.gen.feature.WorldGenMegaJungle;
  21. import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
  22. import net.minecraft.world.gen.feature.WorldGenSavannaTree;
  23. import net.minecraft.world.gen.feature.WorldGenTaiga2;
  24. import net.minecraft.world.gen.feature.WorldGenTrees;
  25. import net.minecraft.world.gen.feature.WorldGenerator;
  26. import net.mod.adamDoesMods.adamDoesMods;
  27. import net.mod.adamDoesMods.Biomes.features.WorldGenAphockTree;
  28.  
  29. public class admSaplings extends BlockSapling {
  30.     public static final String[] saplings = new String[] {"Aphock"};
  31.     private static final IIcon[] icons = new IIcon[saplings.length];
  32.    
  33.     public admSaplings() {
  34.          float var1 = 0.4F;
  35.          this.setBlockBounds(0.5F - var1, 0.0F, 0.5F - var1, 0.5F + var1, var1 * 2.0F, 0.5F + var1);
  36.          this.setCreativeTab(CreativeTabs.tabDecorations);
  37.     }
  38.    
  39.     public void updateTick(World world, int x, int y, int z, Random random)
  40.     {
  41.         if (!world.isRemote)
  42.         {
  43.             super.updateTick(world, x, y, z, random);
  44.  
  45.             if (world.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0)
  46.             {
  47.                 this.func_149879_c(world, x, y, z, random);
  48.             }
  49.         }
  50.     }
  51.    
  52.     public IIcon getIcon(int side, int meta)
  53.     {
  54.         meta &= 7;
  55.         return icons[MathHelper.clamp_int(meta, 0, 5)];
  56.     }
  57.    
  58.     //markOrGrowMarked
  59.     public void func_149879_c(World world, int x, int y, int z, Random random)
  60.     {
  61.         int i = world.getBlockMetadata(x, y, z);
  62.  
  63.         if ((i & 8) == 0)
  64.         {
  65.             world.setBlockMetadataWithNotify(x, y, z, i | 8, 4);
  66.         }
  67.         else
  68.         {
  69.             this.func_149878_d(world, x, y, z, random);
  70.         }
  71.     }
  72.    
  73.     //growTree
  74.     @Override
  75.     public void func_149878_d(World world, int x, int y, int z, Random random)
  76.     {
  77.         if(!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(world, random, x, y, z)) return;
  78.            
  79.        
  80.        
  81.         int var6 = world.getBlockMetadata(x, y, z) & 7;
  82.         Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
  83.         int var8 = 0;
  84.         int var9 = 0;
  85.         boolean var10 = false;
  86.  
  87.         switch (var6)
  88.         {
  89.             case 0:
  90.                 break;
  91.  
  92.             case 1:
  93.                object = new WorldGenAphockTree(adamDoesMods.logs, adamDoesMods.leaves, 0, 0, false, 9, 15, false);
  94.                
  95.                 break;
  96.                
  97.  
  98.             case 3:
  99.                break;
  100.  
  101.             case 4:
  102.                
  103.                 break;
  104.  
  105.             case 5:
  106.                
  107.                break;
  108.            
  109.             default:
  110.                 break;
  111.                
  112.         }
  113.              
  114.  
  115.         Block var11 = Blocks.air;
  116.  
  117.         if (var10)
  118.         {
  119.             world.setBlock(x + var8, y, z + var9, var11, 0, 4);
  120.             world.setBlock(x + var8 + 1, y, z + var9, var11, 0, 4);
  121.             world.setBlock(x + var8, y, z + var9 + 1, var11, 0, 4);
  122.             world.setBlock(x + var8 + 1, y, z + var9 + 1, var11, 0, 4);
  123.         }
  124.         else
  125.         {
  126.             world.setBlock(x, y, z, var11, 0, 4);
  127.         }
  128.  
  129.         if (!((WorldGenerator)object).generate(world, random, x + var8, y, z + var9))
  130.         {
  131.             if (var10)
  132.             {
  133.                 world.setBlock(x + var8, y, z + var9, this, var6, 4);
  134.                 world.setBlock(x + var8 + 1, y, z + var9, this, var6, 4);
  135.                 world.setBlock(x + var8, y, z + var9 + 1, this, var6, 4);
  136.                 world.setBlock(x + var8 + 1, y, z + var9 + 1, this, var6, 4);
  137.             }
  138.             else
  139.             {
  140.                 world.setBlock(x, y, z, this, var6, 4);
  141.             }
  142.         }
  143.     }
  144.     //isSameSapling
  145.     public boolean func_149880_a(World world, int w, int x, int y, int z)
  146.     {
  147.         return world.getBlock(w, x, y) == this && (world.getBlockMetadata(w, x, y) & 7) == z;
  148.     }
  149.  
  150.    
  151.     public int damageDropped(int x)
  152.     {
  153.         return MathHelper.clamp_int(x & 7, 0, 5);
  154.     }
  155.    
  156.     public void getSubBlocks(Item item, CreativeTabs tabs, List list) {
  157.         for(int i = 0; i < saplings.length; i++) {
  158.             list.add(new ItemStack(item, 1, i));
  159.         }
  160.     }
  161.    
  162.     public void registerBlockIcons(IIconRegister register)
  163.     {
  164.         for (int i = 0; i < icons.length; i++)
  165.         {
  166.             icons[i] = register.registerIcon("adamdoesmods" + ":" +"sapling" + saplings[i]);
  167.         }
  168.     }
  169.    
  170.     public boolean func_149851_a(World world, int x, int y, int z, boolean myBoolean)
  171.     {
  172.         return true;
  173.     }
  174.    
  175.     public boolean func_149852_a(World world, Random random, int x, int y, int z)
  176.     {
  177.         return (double)world.rand.nextFloat() < 0.45D;
  178.     }
  179.    
  180.     public void func_149853_b(World world, Random random, int x, int y, int z)
  181.     {
  182.         this.func_149879_c(world, x, y, z, random);
  183.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement