Advertisement
Chiddix

TallGrassWorldGenerator

Apr 26th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package com.mojang.minecraft.world.gen.impl;
  2.  
  3. import java.util.Random;
  4.  
  5. /**
  6.  * A world generator which generates tall grass.
  7.  * @author Ryan Greene
  8.  *
  9.  */
  10. public class TallGrassWorldGenerator extends WorldGenerator {
  11.  
  12.     /**
  13.      * The id of the grass block which is being generated.
  14.      */
  15.     private final int grassBlockId;
  16.  
  17.     /**
  18.      * The metadata of the grass block which is being generated.
  19.      */
  20.     private final int grassMetadata;
  21.  
  22.     /**
  23.      * Constructs a new tall grass world generator with the specified grass id and metadata.
  24.      * @param grassBlockId The id of the grass block which is being generated
  25.      * @param grassMetadata The metadata of the grass block which is being generated
  26.      */
  27.     public TallGrassWorldGenerator(final int grassBlockId, final int grassMetadata) {
  28.         this.grassBlockId = grassBlockId;
  29.         this.grassMetadata = grassMetadata;
  30.     }
  31.  
  32.     @Override
  33.     public boolean generate(final World world, final Random random, final int x, int y, final int z) {
  34.         for (int attempt = 0; attempt < 128; attempt++) {
  35.             final int grassX = x + random.nextInt(8) - random.nextInt(8);
  36.             final int grassY = y + random.nextInt(4) - random.nextInt(4);
  37.             final int grassZ = z + random.nextInt(8) - random.nextInt(8);
  38.             if (world.isAirBlock(grassX, grassY, grassZ) && ((BlockFlower) Block.blocksList[grassBlockId]).canBlockStay(world, grassX, grassY, grassZ)) {
  39.                 world.setBlockAndMetadata(grassX, grassY, grassZ, grassBlockId, grassMetadata);
  40.             }
  41.         }
  42.  
  43.         return true;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement