Progress on Maze Generation
* Increased the chance of decorating unprotected rooms from 1/4 to 1/3. * Made minor optimizations to the box building function. * Added some important arguments to BaseDecorator.decorate(). Also updated all decorators as a result of this change. * Implemented TorchDecorator so that mazes have light sources in them.
This commit is contained in:
@@ -17,7 +17,7 @@ public class MazeBuilder
|
||||
{
|
||||
private static final int POCKET_WALL_GAP = 4;
|
||||
private static final int DECORATION_CHANCE = 1;
|
||||
private static final int MAX_DECORATION_CHANCE = 4;
|
||||
private static final int MAX_DECORATION_CHANCE = 3;
|
||||
|
||||
private MazeBuilder() { }
|
||||
|
||||
@@ -142,11 +142,11 @@ public class MazeBuilder
|
||||
decorator = DecoratorFinder.find(room, random);
|
||||
if (decorator != null)
|
||||
{
|
||||
decorator.decorate(room, random, properties);
|
||||
decorator.decorate(room, world, offset, random, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Iterate over all links plans and place links in the world
|
||||
// Iterate over all link plans and place links in the world
|
||||
for (LinkPlan link : links)
|
||||
{
|
||||
// TODO: Add link placement code here!
|
||||
@@ -323,15 +323,15 @@ public class MazeBuilder
|
||||
}
|
||||
for (x = minX; x <= maxX; x++)
|
||||
{
|
||||
for (y = minY; y <= maxY; y++)
|
||||
for (y = minY + 1; y < maxY; y++)
|
||||
{
|
||||
setBlockDirectly(world, x, y, minZ, blockID, metadata);
|
||||
setBlockDirectly(world, x, y, maxZ, blockID, metadata);
|
||||
}
|
||||
}
|
||||
for (z = minZ; z <= maxZ; z++)
|
||||
for (z = minZ + 1; z < maxZ; z++)
|
||||
{
|
||||
for (y = minY; y <= maxY; y++)
|
||||
for (y = minY + 1; y < maxY; y++)
|
||||
{
|
||||
setBlockDirectly(world, minX, y, z, blockID, metadata);
|
||||
setBlockDirectly(world, maxX, y, z, blockID, metadata);
|
||||
|
||||
@@ -2,7 +2,9 @@ package StevenDimDoors.experimental.decorators;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.experimental.RoomData;
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
|
||||
public abstract class BaseDecorator
|
||||
@@ -11,5 +13,5 @@ public abstract class BaseDecorator
|
||||
|
||||
public abstract boolean canDecorate(RoomData room);
|
||||
|
||||
public abstract boolean decorate(RoomData room, Random random, DDProperties properties);
|
||||
public abstract void decorate(RoomData room, World world, Point3D offset, Random random, DDProperties properties);
|
||||
}
|
||||
|
||||
@@ -2,22 +2,24 @@ package StevenDimDoors.experimental.decorators;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import StevenDimDoors.experimental.RoomData;
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
|
||||
public class DefaultDoorDecorator extends BaseDecorator {
|
||||
|
||||
public class DefaultDoorDecorator extends BaseDecorator
|
||||
{
|
||||
@Override
|
||||
public boolean canDecorate(RoomData room) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean canDecorate(RoomData room)
|
||||
{
|
||||
return !room.getOutboundLinks().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decorate(RoomData room, Random random,
|
||||
DDProperties properties) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public void decorate(RoomData room, World world, Point3D offset, Random random, DDProperties properties)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,22 +2,23 @@ package StevenDimDoors.experimental.decorators;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import StevenDimDoors.experimental.RoomData;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import StevenDimDoors.experimental.RoomData;
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
|
||||
public class LinkDestinationDecorator extends BaseDecorator
|
||||
{
|
||||
@Override
|
||||
public boolean canDecorate(RoomData room) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean canDecorate(RoomData room)
|
||||
{
|
||||
return room.getOutboundLinks().isEmpty() && !room.getInboundLinks().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decorate(RoomData room, Random random,
|
||||
DDProperties properties) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public void decorate(RoomData room, World world, Point3D offset, Random random, DDProperties properties)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,85 @@ package StevenDimDoors.experimental.decorators;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import StevenDimDoors.experimental.PartitionNode;
|
||||
import StevenDimDoors.experimental.RoomData;
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
|
||||
public class TorchDecorator extends BaseDecorator {
|
||||
|
||||
public class TorchDecorator extends BaseDecorator
|
||||
{
|
||||
@Override
|
||||
public boolean canDecorate(RoomData room) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean canDecorate(RoomData room)
|
||||
{
|
||||
return !room.isProtected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decorate(RoomData room, Random random,
|
||||
DDProperties properties) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public void decorate(RoomData room, World world, Point3D offset, Random random, DDProperties properties)
|
||||
{
|
||||
// SenseiKiwi: Place a single random torch along the walls.
|
||||
// We could do more complex arrangements but I feel that a single
|
||||
// torches here and there will be a little unsettling.
|
||||
// The walls might be broken by passages or decay, so this will
|
||||
// require trial and error.
|
||||
|
||||
final int MAX_ATTEMPTS = 5;
|
||||
|
||||
int x;
|
||||
int z;
|
||||
int attempts = 0;
|
||||
PartitionNode<RoomData> partition = room.getPartitionNode();
|
||||
int minX = partition.minCorner().getX() + offset.getX();
|
||||
int minZ = partition.minCorner().getZ() + offset.getZ();
|
||||
int maxX = partition.maxCorner().getX() + offset.getX();
|
||||
int maxZ = partition.maxCorner().getZ() + offset.getZ();
|
||||
int torchLevel = partition.minCorner().getY() + offset.getY() + 2;
|
||||
|
||||
for (; attempts < MAX_ATTEMPTS; attempts++)
|
||||
{
|
||||
// Choose a random side of the room to place the torch. The sides are numbered arbitrarily here.
|
||||
// Then choose a random position along the wall and check if there is a block there to place the
|
||||
// torch against. We assume that all blocks are bricks and thus valid.
|
||||
switch (random.nextInt(4))
|
||||
{
|
||||
case 0: // Positive X side
|
||||
z = MathHelper.getRandomIntegerInRange(random, minZ + 1, maxZ - 1);
|
||||
if (!world.isAirBlock(maxX, torchLevel, z))
|
||||
{
|
||||
world.setBlock(maxX - 1, torchLevel, z, Block.torchWood.blockID, 2, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1: // Negative X side
|
||||
z = MathHelper.getRandomIntegerInRange(random, minZ + 1, maxZ - 1);
|
||||
if (!world.isAirBlock(minX, torchLevel, z))
|
||||
{
|
||||
world.setBlock(minX + 1, torchLevel, z, Block.torchWood.blockID, 1, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2: // Positive Z side
|
||||
x = MathHelper.getRandomIntegerInRange(random, minX + 1, maxX - 1);
|
||||
if (!world.isAirBlock(x, torchLevel, maxZ))
|
||||
{
|
||||
world.setBlock(x, torchLevel, maxZ - 1, Block.torchWood.blockID, 4, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3: // Negative Z side
|
||||
x = MathHelper.getRandomIntegerInRange(random, minX + 1, maxX - 1);
|
||||
if (!world.isAirBlock(x, torchLevel, minZ))
|
||||
{
|
||||
world.setBlock(x, torchLevel, minZ + 1, Block.torchWood.blockID, 3, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user