Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomSort implements Comparator<IBlockState> {
- @Override
- public int compare(IBlockState arg0, IBlockState arg1) {
- return arg0.getBlock().toString().compareTo(arg1.getBlock().toString()); // Sort in alphebetical order.
- }
- }
- public class Generate implements IWorldGenerator {
- int Min = 0;
- int Max = 128;
- int Range = Max-Min+1;
- @Override
- public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
- IChunkProvider chunkProvider) {
- // TODO Auto-generated method stub
- for (int X = 0; X < 16; X++)
- {
- for (int Z = 0; Z < 16; Z++)
- {
- IBlockState[] Main = new IBlockState[Range]; // Main array. (Sorry if I say table on accident anywhere, used to Lua)
- List<IBlockState> B = new ArrayList<IBlockState>(); // Array for sorting blocks, so we leave lava, water, and air where they are.
- for (int Y = Min; Y < Max; Y++) // Min and max were originally to test because I thought it would take hours to generate.
- {
- Main[Y-Min] = chunkProvider.getLoadedChunk(chunkX, chunkZ).getBlockState(X, Y, Z); // Add the block to the array.
- }
- int Pos = 0;
- for (int I = 0; I < Range; I++) // Add blocks that are not water, lava, or air to the sorting array.
- {
- // This next like is some ugly hard-coding, but I really am not up to doing anything about it for the time being.
- if (Main[I] != null && Main[I].getBlock() != Blocks.AIR && Main[I].getBlock() != Blocks.WATER && Main[I].getBlock() != Blocks.LAVA)
- {
- B.add(Main[I]);
- Pos++; // Increment the position only after we know that it is a valid sortable block.
- }
- }
- Pos = 0;
- Collections.sort(B, new CustomSort()); // Sort it with the function above.
- for (int I = 0; I < Range; I++) // This loop puts the stuff back in the array Main.
- {
- // This preserves the structure and shape of liquids and air.
- if (Main[I] != null && Main[I].getBlock() != Blocks.AIR && Main[I].getBlock() != Blocks.WATER && Main[I].getBlock() != Blocks.LAVA) {
- Main[I] = B.get(Pos);
- Pos++;
- }
- }
- for (int Y = Min; Y < Max; Y++)
- {
- chunkProvider.getLoadedChunk(chunkX, chunkZ).setBlockState(new BlockPos(X, Y, Z), Main[Y-Min]); // Main contains IBlockStates, making this easy.
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment