Improved Rift Gateway Generation and Fixed Several Bugs #26
@@ -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
|
||||||
@@ -77,15 +80,22 @@ public class RiftGenerator implements IWorldGenerator
|
|||||||
//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)
|
||||||
{
|
{
|
||||||
//Pick a random point on the surface of the chunk
|
//Check locations for the gateway until we are satisfied or run out of attempts.
|
||||||
x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
|
attempts = 0;
|
||||||
z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
|
valid = false;
|
||||||
y = world.getHeightValue(x, z);
|
do
|
||||||
|
{
|
||||||
|
//Pick a random point on the surface of the chunk
|
||||||
|
x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
|
||||||
|
z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH);
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user