Added Nether Gateway Chance Correction

Modified RiftGenerator to correct for the rarity of Rift Gateways in the
Nether. Our config settings allow us to set the probability that we will
attempt to generate a gateway in a given chunk. However, that doesn't
guarantee that a gateway will generate.

I collected a lot of data and determined that generation succeeds in the
Nether only about 15% of the time. That's compared to 30% in the
Overworld when counting oceans (which always fail) and about 75%
(sometimes higher) when traveling mainly on land.

RiftGenerator now corrects for this by multiplying the chance of
attempting to generate gateways in the Nether by 4. Gateways in the
Nether are still relatively rare and hard to find, but you'll
occasionally come across them now. Also reorganized the code a little
for clarify.
This commit is contained in:
SenseiKiwi
2013-08-07 22:11:10 -04:00
parent 68bf4a16c1
commit 6b69d3d138

View File

@@ -24,6 +24,9 @@ public class RiftGenerator implements IWorldGenerator
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 = 10; private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10;
private static final int NETHER_CHANCE_CORRECTION = 4;
private static final int OVERWORLD_DIMENSION_ID = 0;
private static final int NETHER_DIMENSION_ID = -1;
private static DDProperties properties = null; private static DDProperties properties = null;
public RiftGenerator() public RiftGenerator()
@@ -43,17 +46,31 @@ public class RiftGenerator implements IWorldGenerator
return; return;
} }
//This check prevents a crash related to superflat worlds not loading World 0 //This check prevents a crash related to superflat worlds not loading World 0
if (dimHelper.getWorld(0) == null) if (dimHelper.getWorld(OVERWORLD_DIMENSION_ID) == null)
{ {
return; return;
} }
int x, y, z; int x, y, z;
int attempts; int attempts;
int blockID; int correction;
boolean valid; boolean valid;
LinkData link; LinkData link;
//Check if we're generating things in the Nether
if (world.provider.dimensionId == NETHER_DIMENSION_ID)
{
//The terrain in the Nether makes it much harder for our gateway spawning algorithm to find a spot to place a gateway.
//Tests show that only about 15% of attempts succeed. Compensate for this by multiplying the chance of generation
//by a correction factor.
correction = NETHER_CHANCE_CORRECTION;
}
else
{
//No correction
correction = 1;
}
//Randomly decide whether to place a cluster of rifts here //Randomly decide whether to place a cluster of rifts here
if (random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance) if (random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance)
{ {
@@ -91,7 +108,8 @@ public class RiftGenerator implements IWorldGenerator
//Check if generating structures is enabled and randomly decide whether to place a Rift Gateway here. //Check if generating structures is enabled and 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 && isStructureGenerationAllowed()) else if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance * correction &&
isStructureGenerationAllowed())
{ {
valid = false; valid = false;
x = y = z = 0; //Stop the compiler from freaking out x = y = z = 0; //Stop the compiler from freaking out
@@ -117,7 +135,22 @@ public class RiftGenerator implements IWorldGenerator
//If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks
if (world.provider.dimensionId != properties.LimboDimensionID) if (world.provider.dimensionId != properties.LimboDimensionID)
{ {
blockID = Block.stoneBrick.blockID; createStoneGateway(world, x, y, z, random);
}
else
{
createLimboGateway(world, x, y, z);
}
//Place the shiny transient door into a dungeon
itemDimDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor);
}
}
}
private static void createStoneGateway(World world, int x, int y, int z, Random random)
{
final int blockID = Block.stoneBrick.blockID;
//Replace some of the ground around the gateway with bricks //Replace some of the ground around the gateway with bricks
for (int xc = -GATEWAY_RADIUS; xc <= GATEWAY_RADIUS; xc++) for (int xc = -GATEWAY_RADIUS; xc <= GATEWAY_RADIUS; xc++)
@@ -148,26 +181,26 @@ public class RiftGenerator implements IWorldGenerator
//Use Chiseled Stone Bricks to top off the pillars around the door //Use Chiseled Stone Bricks to top off the pillars around the door
world.setBlock(x, y + 2, z + 1, blockID, 3, 3); world.setBlock(x, y + 2, z + 1, blockID, 3, 3);
world.setBlock(x, y + 2, z - 1, blockID, 3, 3); world.setBlock(x, y + 2, z - 1, blockID, 3, 3);
}
else
{
//Build the gateway out of Unraveled Fabric. Since nearly all the blocks in Limbo are of
//that type, there is no point replacing the ground. Just build the tops of the columns here.
blockID = properties.LimboBlockID;
world.setBlock(x, y + 2, z + 1, blockID, 0, 3);
world.setBlock(x, y + 2, z - 1, blockID, 0, 3);
}
//Place the shiny transient door into a dungeon
itemDimDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor);
//Build the columns around the door //Build the columns around the door
world.setBlock(x, y + 1, z - 1, blockID, 0, 3); world.setBlock(x, y + 1, z - 1, blockID, 0, 3);
world.setBlock(x, y + 1, z + 1, blockID, 0, 3); world.setBlock(x, y + 1, z + 1, blockID, 0, 3);
world.setBlock(x, y, z - 1, blockID, 0, 3); world.setBlock(x, y, z - 1, blockID, 0, 3);
world.setBlock(x, y, z + 1, blockID, 0, 3); world.setBlock(x, y, z + 1, blockID, 0, 3);
} }
}
private static void createLimboGateway(World world, int x, int y, int z)
{
//Build the gateway out of Unraveled Fabric. Since nearly all the blocks in Limbo are of
//that type, there is no point replacing the ground.
final int blockID = properties.LimboBlockID;
world.setBlock(x, y + 2, z + 1, blockID, 0, 3);
world.setBlock(x, y + 2, z - 1, blockID, 0, 3);
//Build the columns around the door
world.setBlock(x, y + 1, z - 1, blockID, 0, 3);
world.setBlock(x, y + 1, z + 1, blockID, 0, 3);
world.setBlock(x, y, z - 1, blockID, 0, 3);
world.setBlock(x, y, z + 1, blockID, 0, 3);
} }
private static boolean checkGatewayLocation(World world, int x, int y, int z) private static boolean checkGatewayLocation(World world, int x, int y, int z)
@@ -195,6 +228,6 @@ public class RiftGenerator implements IWorldGenerator
private static boolean isStructureGenerationAllowed() private static boolean isStructureGenerationAllowed()
{ {
return DimensionManager.getWorld(0).getWorldInfo().isMapFeaturesEnabled(); return DimensionManager.getWorld(OVERWORLD_DIMENSION_ID).getWorldInfo().isMapFeaturesEnabled();
} }
} }