Advertisement
Guest User

Here

a guest
Sep 14th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.47 KB | None | 0 0
  1. package Mod.init.blocks.world.feature.tree;
  2.  
  3. import java.util.Random;
  4.  
  5. import Mod.init.BlockInit;
  6. import Mod.init.blocks.trees.CustomBlockLeaves;
  7. import Mod.init.blocks.trees.CustomBlockLog;
  8. import Mod.init.blocks.trees.CustomBlockPlanks;
  9. import Mod.init.blocks.trees.CustomBlockSapling;
  10. import net.minecraft.block.state.IBlockState;
  11. import net.minecraft.util.EnumFacing;
  12. import net.minecraft.util.math.BlockPos;
  13. import net.minecraft.world.World;
  14. import net.minecraft.world.gen.feature.WorldGenAbstractTree;
  15.  
  16. public class WorldGenInsaneTree extends WorldGenAbstractTree {
  17.  
  18.     public static final IBlockState LOG = BlockInit.log.getDefaultState().withProperty(CustomBlockLog.VARIANT, CustomBlockPlanks.EnumType.INSANE);
  19.     public static final IBlockState LEAF = BlockInit.leaves.getDefaultState().withProperty(CustomBlockLeaves.VARIANT, CustomBlockPlanks.EnumType.INSANE);
  20.    
  21.     private int minHeight;
  22.    
  23.     public WorldGenInsaneTree() {
  24.         super(false);
  25.         this.minHeight = 13;
  26.     }
  27.  
  28.     @Override
  29.     public boolean generate(World world, Random rand, BlockPos pos) {
  30.         int height = this.minHeight + rand.nextInt(3);
  31.         boolean flag = true;
  32.        
  33.         int x = pos.getX();
  34.         int y = pos.getY();
  35.         int z = pos.getZ();
  36.        
  37.         for (int yPos = y; yPos <= y + 1 + height; yPos++) {
  38.             int b0 = 2;
  39.             if (yPos == y || yPos == y + 1) b0 = 0;
  40.            
  41.             BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
  42.            
  43.             for (int xPos = x - b0; xPos <= x + b0 && flag; xPos++) {
  44.                 for (int zPos = z - b0; zPos <= z + b0 && flag; zPos++) {
  45.                     if (yPos >= 0 && yPos < world.getHeight()) {
  46.                         if (!this.isReplaceable(world, new BlockPos(xPos, yPos, zPos))) {
  47.                             flag = false;
  48.                         }
  49.                     } else {
  50.                         flag = false;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.        
  56.         if (!flag) {
  57.             return false;
  58.         } else {
  59.             BlockPos down = pos.down();
  60.             IBlockState state = world.getBlockState(down);
  61.             boolean isSoil = state.getBlock().canSustainPlant(state, world, down, EnumFacing.UP, (CustomBlockSapling)BlockInit.sapling);
  62.            
  63.             if (isSoil && y < world.getHeight() - height - 1) {
  64.                 state.getBlock().onPlantGrow(state, world, down, pos);
  65.                
  66.                 for (int yPos = y - 3 + height; yPos <= y + height; yPos++) {
  67.                     int b1 = yPos - (y + height);
  68.                     int b2 = 1 - b1 / 2;
  69.                    
  70.                     for (int xPos = x - b2; xPos <= x + b2; xPos++) {
  71.                         int b3 = xPos - x;
  72.                         for (int zPos = z - b2; zPos <= z + b2; zPos++) {
  73.                             int b4 = zPos - z;
  74.                             if (Math.abs(b3) != b2 || Math.abs(b4) != b2 || rand.nextInt(2) != 0 && b1 != 0) {
  75.                                 BlockPos treePos = new BlockPos(xPos, yPos, zPos);
  76.                                 IBlockState treeState = world.getBlockState(treePos);
  77.                                 if (treeState.getBlock().isAir(treeState, world, treePos) || treeState.getBlock().isAir(treeState, world, treePos)) {
  78.                                     this.setBlockAndNotifyAdequately(world, treePos, LEAF);
  79.                                     this.setBlockAndNotifyAdequately(world, treePos.add(0, -0.25 * height, 0), LEAF);
  80.                                     this.setBlockAndNotifyAdequately(world, treePos.add(0, -0.5 * height, 0), LEAF);
  81.                                 }
  82.                             }
  83.                         }
  84.                     }
  85.                 }
  86.                
  87.                 for (int logHeight = 0; logHeight < height; logHeight++) {
  88.                     BlockPos up = pos.up(logHeight);
  89.                     IBlockState logState = world.getBlockState(up);
  90.                    
  91.                     if (logState.getBlock().isAir(logState, world, up) || logState.getBlock().isLeaves(logState, world, up)) {
  92.                         this.setBlockAndNotifyAdequately(world, pos.up(logHeight), LOG);
  93.                        
  94.                     }
  95.                 }
  96.                
  97.                 return true;
  98.             }
  99.         }
  100.        
  101.         return true;
  102.     }
  103.  
  104.    
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement