Improved Rift Gateway Generation and Fixed Several Bugs #26

Merged
SenseiKiwi merged 7 commits from master into master 2013-06-17 21:16:09 +00:00
Showing only changes of commit 4ceace1b47 - Show all commits

View File

@@ -20,6 +20,7 @@ public class RiftGenerator implements IWorldGenerator
private static final int MAX_RIFT_Y = 250; private static final int MAX_RIFT_Y = 250;
private static final int CHUNK_LENGTH = 16; private static final int CHUNK_LENGTH = 16;
private static final int GATEWAY_RADIUS = 4; private static final int GATEWAY_RADIUS = 4;
private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 6;
private static DDProperties properties = null; private static DDProperties properties = null;
public RiftGenerator() public RiftGenerator()
@@ -39,7 +40,9 @@ public class RiftGenerator implements IWorldGenerator
} }
int x, y, z; int x, y, z;
int attempts;
int blockID; int blockID;
boolean valid;
LinkData link; LinkData link;
//Randomly decide whether to place a cluster of rifts here //Randomly decide whether to place a cluster of rifts here
@@ -76,16 +79,23 @@ public class RiftGenerator implements IWorldGenerator
//Randomly decide whether to place a Rift Gateway here. //Randomly decide whether to place a Rift Gateway here.
//This only happens if a rift cluster was NOT generated. //This only happens if a rift cluster was NOT generated.
else if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance) else if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance)
{
//Check locations for the gateway until we are satisfied or run out of attempts.
attempts = 0;
valid = false;
do
{ {
//Pick a random point on the surface of the chunk //Pick a random point on the surface of the chunk
x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
y = world.getHeightValue(x, z); y = world.getHeightValue(x, z);
valid = checkGatewayLocation(world, x, y, z);
attempts++;
}
while (attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && valid);
//Check if the point is within the acceptable altitude range, the block above that point is empty, //Build the gateway if we found a valid location
//and at least one of the two blocks under that point are opaque if (valid)
if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) &&
world.isBlockOpaqueCube(x, y - 2, z) || world.isBlockOpaqueCube(x, y - 1, z))
{ {
//Create a two-way link between the upper block of the gateway and a pocket dimension //Create a two-way link between the upper block of the gateway and a pocket dimension
//That pocket dimension is where we'll start a dungeon! //That pocket dimension is where we'll start a dungeon!
@@ -147,4 +157,12 @@ public class RiftGenerator implements IWorldGenerator
} }
} }
} }
private static boolean checkGatewayLocation(World world, int x, int y, int z)
{
//Check if the point is within the acceptable altitude range, the block above that point is empty,
//and at least one of the two blocks under that point are opaque
return (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) &&
world.isBlockOpaqueCube(x, y - 2, z) || world.isBlockOpaqueCube(x, y - 1, z));
}
} }