GenuineSounds

Maximum Height in Chunk

Sep 26th, 2014
398
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.genuineminecraft.ores.generator;
  2.  
  3. import net.minecraft.init.Blocks;
  4. import net.minecraft.world.chunk.Chunk;
  5.  
  6. public class Utility {
  7.  
  8.     public static int findHighestBlock(Chunk chunk) {
  9.         // Check once downward.
  10.         int yMax = 255;
  11.         for (int yCheck = yMax; yCheck > 0; yCheck--) {
  12.             if (chunk.getBlock(7, yCheck, 7).equals(Blocks.air))
  13.                 yMax--;
  14.             else
  15.                 break;
  16.         }
  17.         // Check above first downward test.
  18.         boolean firstTry;
  19.         search:
  20.         for (int y = yMax; y > 0; y--) {
  21.             firstTry = true;
  22.             for (int x = 0; x < 16; x++) {
  23.                 for (int z = 0; z < 16; z++) {
  24.                     if (chunk.getBlock(x, y, z).equals(Blocks.air))
  25.                         if (firstTry) {
  26.                             yMax = y + 10;
  27.                             // Retry if found on first try of new yMax.
  28.                             break search;
  29.                         } else
  30.                             yMax = y;
  31.                     else
  32.                         break;
  33.                 }
  34.             }
  35.             firstTry = false;
  36.         }
  37.         return yMax;
  38.     }
  39. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment