diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index 6a72de7..99d85f2 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; @@ -20,7 +21,7 @@ public class RiftGenerator implements IWorldGenerator private static final int MAX_RIFT_Y = 250; private static final int CHUNK_LENGTH = 16; private static final int GATEWAY_RADIUS = 4; - private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 6; + private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10; private static DDProperties properties = null; public RiftGenerator() @@ -56,8 +57,12 @@ public class RiftGenerator implements IWorldGenerator z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); y = world.getHeightValue(x, z); - //If the point is within the acceptable altitude range and the block above is empty, then place a rift - if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z)) + //If the point is within the acceptable altitude range, the block above is empty, and we're + //not building on bedrock, then generate a rift there + if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) && + world.getBlockId(x, y, z) != Block.bedrock.blockID && //<-- Stops Nether roof spawning. DO NOT REMOVE! + world.getBlockId(x, y - 1, z) != Block.bedrock.blockID && + world.getBlockId(x, y - 2, z) != Block.bedrock.blockID) { //Create a link. If this is the first time, create a dungeon pocket and create a two-way link. //Otherwise, create a one-way link and connect to the destination of the first link. @@ -80,19 +85,18 @@ public class RiftGenerator implements IWorldGenerator //This only happens if a rift cluster was NOT generated. 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 + x = y = z = 0; //Stop the compiler from freaking out + + //Check locations for the gateway until we are satisfied or run out of attempts. + for (attempts = 0; attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && !valid; attempts++) { - //Pick a random point on the surface of the chunk + //Pick a random point on the surface of the chunk and check its materials 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); //Build the gateway if we found a valid location if (valid) @@ -161,8 +165,23 @@ 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)); + //and the block two levels down is opaque and has a reasonable material. Plus that we're not building + //on top of bedrock. + return (y >= MIN_RIFT_Y && + y <= MAX_RIFT_Y && + world.isAirBlock(x, y + 1, z) && + world.getBlockId(x, y, z) != Block.bedrock.blockID && //<-- Stops Nether roof spawning. DO NOT REMOVE! + world.getBlockId(x, y - 1, z) != Block.bedrock.blockID && + checkFoundationMaterial(world, x, y - 2, z)); + } + + private static boolean checkFoundationMaterial(World world, int x, int y, int z) + { + //We check the material and opacity to prevent generating gateways on top of trees or houses, + //or on top of strange things like tall grass, water, slabs, or torches. + //We also want to avoid generating things on top of the Nether's bedrock! + Material material = world.getBlockMaterial(x, y, z); + return (material != Material.leaves && material != Material.wood && material != Material.pumpkin + && world.isBlockOpaqueCube(x, y, z) && world.getBlockId(x, y, z) != Block.bedrock.blockID); } }