package net.glowstone.generator.decorators.overworld;

import java.util.Random;
import net.glowstone.generator.decorators.BlockDecorator;
import net.glowstone.generator.objects.SugarCane;
import org.bukkit.Chunk;
import org.bukkit.World;

public class SugarCaneDecorator extends BlockDecorator {

    @Override
    public void decorate(World world, Random random, Chunk source) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
        for (int j = 0; j < 20; j++) {
            int x = sourceX + random.nextInt(4) - random.nextInt(4);
            int z = sourceZ + random.nextInt(4) - random.nextInt(4);
            new SugarCane().generate(world, random, x, sourceY, z);
        }
    }
}

@@ -519,33 +519,15 @@
 int 
-sourceY = random.nextInt(
+maxY = 
 worl
@@ -568,16 +568,87 @@
 ceZ)
+;%0A        if (maxY %3E 0) %7B%0A            int sourceY = random.nextInt(maxY
  %3C%3C 1);%0A
     
@@ -643,16 +643,20 @@
  %3C%3C 1);%0A
+    
         
@@ -694,24 +694,28 @@
             
+   
+ 
 int x = sour
@@ -751,32 +751,36 @@
 dom.nextInt(4);%0A
+    
             int 
@@ -844,16 +844,20 @@
         
+   
+ 
 new Suga
@@ -904,16 +904,30 @@
 eY, z);%0A
+            %7D%0A
         

Fix an exception from SugarCaneDecorator in holey worlds