Official Redstone Wars Tournament plugin: World Generator

RedstonerOther → Official Redstone Wars Tournament plugin: World Generator

I’ve pretty much finished writing the first version of the world generator of the plugin I’m making for the idea seen here: http://redstoner.com/forums/threads/629-the-official-redstone-wars-tournament

package co.dico.tournament.handlers;

import java.util.Random;

import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;

public class WorldGen extends ChunkGenerator {
	
	@Override
	public short[][] generateExtBlockSections(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {		
		short filling = 24;
		short bottom = 7;
		short wall = 44;
		short pathside = 174;
		short floor = 24;
		short pathcenter = 159;
		
		int height = world.getMaxHeight();
		short[][] result = new short[height / 16][];
		
		for (int i = 0; i < 16; i++)
			result[i] = new short[4096];
		
		int plotPartX = chunkX % 4;
		int plotPartZ = chunkZ % 4;
		if (plotPartX < 0)
			plotPartX += 4;
		if (plotPartZ < 0)
			plotPartX += 4;
		int absoluteX = plotPartX * 16;
		int absoluteZ = plotPartZ * 16;
		int totalX;
		int totalZ;
		
		for (int x = 0; x < 15; x++) {
			totalX = absoluteX + x;
			z:for (int z = 0; z < 15; z++) {
				totalZ = absoluteZ + z;
				setBlock(result, x, 0, z, bottom);
				biomeGrid.setBiome(x, z, Biome.PLAINS);
				for (int y = 1; y <= 62; y++)
					setBlock(result, x, y, z, filling);
				if (inRange(totalX, 3, 61 ) && inRange(totalZ, 3, 61)) {
					setBlock(result, x, 63, z, floor);
					if ((totalX == 3 || totalX == 61) && (totalZ == 3 || totalZ == 61))
						setBlock(result, x, 64, z, wall);
					continue z;
				}
				if ((totalX == 2 || totalX == 62) && (totalZ == 2 || totalZ == 62)) {
					setBlock(result, x, 63, z, pathside);
					continue z;
				}
				setBlock(result, x, 63, z, pathcenter);				
			}
		}
		return result;
	}
	
	public static boolean inRange(int x, int min, int max) {
		return (min <= x && x <= max);
	}

	void setBlock(short[][] result, int x, int y, int z, short id) {
		result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = id;
	}
}

The generateExtBlockSeconds() method is called when a chunk needs to be generated. it returns an array of 16 short[] arrays. each short[] array contains the values for a 16x16x16 area and is stacked on top of the previous one. At the top of the method I defined the id’s for each part of the plot world (this is a plot world generator). Each plot should be 57x57 with 5 wide paths inbetween, excluding plot border, so each plot + surrounding paths will be 4x4 chunks // 64x64. The method starts from the middle of a path cross section, hence the point 0,0 in the world will be in the center of 4 plots.

If you have any ideas what I should change, especially regarding the plot materials, feel free to comment below.

174 is packed ice, 159 is stained clay. this will be white, I dont know how to set data values yet. 44 is stone slabs. 24 is sandstone, 7 is bedrock :)

Edit: I think I might know which plugin is causing my world not to load. Who knows… Pic

Another edit: LOL I DIDNT GET THE NEW VERSION FROM MY LAPTOP.

When I fixed that dumb problem… well. Closer than expected! pic

The problem is real.

for (int x = 0; x < 15; x++) { totalX = absoluteX + x; z:for (int z = 0; z < 15; z++) {

lol. chunks are not 15x15, they’re 16x16. Thats #1 fixed.

Making progress. Omg I’m so liking this (this is my first worldgen ever) pic
Looking good dico :D