Added Maze Decorators
Added Decorators for use in mazes. I've added several decorators but all of them are stubs for now.
This commit is contained in:
@@ -8,12 +8,16 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
import StevenDimDoors.experimental.decorators.BaseDecorator;
|
||||||
|
import StevenDimDoors.experimental.decorators.DecoratorFinder;
|
||||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||||
|
|
||||||
public class MazeBuilder
|
public class MazeBuilder
|
||||||
{
|
{
|
||||||
private static final int POCKET_WALL_GAP = 4;
|
private static final int POCKET_WALL_GAP = 4;
|
||||||
|
private static final int DECORATION_CHANCE = 1;
|
||||||
|
private static final int MAX_DECORATION_CHANCE = 4;
|
||||||
|
|
||||||
private MazeBuilder() { }
|
private MazeBuilder() { }
|
||||||
|
|
||||||
@@ -28,7 +32,7 @@ public class MazeBuilder
|
|||||||
buildRooms(design.getLayout(), world, offset);
|
buildRooms(design.getLayout(), world, offset);
|
||||||
carveDoorways(design.getLayout(), world, offset, decay, random);
|
carveDoorways(design.getLayout(), world, offset, decay, random);
|
||||||
applyRandomDestruction(design, world, offset, decay, random);
|
applyRandomDestruction(design, world, offset, decay, random);
|
||||||
decorateRooms(design.getLayout(), world, offset);
|
decorateRooms(design.getLayout(), world, offset, random, properties);
|
||||||
buildPocketWalls(design, world, offset, properties);
|
buildPocketWalls(design, world, offset, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +121,11 @@ public class MazeBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void decorateRooms(DirectedGraph<RoomData, DoorwayData> layout, World world, Point3D offset)
|
private static void decorateRooms(DirectedGraph<RoomData, DoorwayData> layout,
|
||||||
|
World world, Point3D offset, Random random, DDProperties properties)
|
||||||
{
|
{
|
||||||
RoomData room;
|
RoomData room;
|
||||||
|
BaseDecorator decorator;
|
||||||
PartitionNode<RoomData> partition;
|
PartitionNode<RoomData> partition;
|
||||||
ArrayList<LinkPlan> links = new ArrayList<LinkPlan>();
|
ArrayList<LinkPlan> links = new ArrayList<LinkPlan>();
|
||||||
|
|
||||||
@@ -129,8 +135,16 @@ public class MazeBuilder
|
|||||||
room = node.data();
|
room = node.data();
|
||||||
partition = room.getPartitionNode();
|
partition = room.getPartitionNode();
|
||||||
links.addAll(room.getOutboundLinks());
|
links.addAll(room.getOutboundLinks());
|
||||||
|
// Protected rooms must be decorated because they have links.
|
||||||
// TODO: Add decorator code here!
|
// Otherwise, choose randomly whether to decorate.
|
||||||
|
if (room.isProtected() && random.nextInt(MAX_DECORATION_CHANCE) < DECORATION_CHANCE)
|
||||||
|
{
|
||||||
|
decorator = DecoratorFinder.find(room, random);
|
||||||
|
if (decorator != null)
|
||||||
|
{
|
||||||
|
decorator.decorate(room, random, properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Iterate over all links plans and place links in the world
|
// Iterate over all links plans and place links in the world
|
||||||
for (LinkPlan link : links)
|
for (LinkPlan link : links)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package StevenDimDoors.experimental.decorators;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import StevenDimDoors.experimental.RoomData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||||
|
|
||||||
|
public abstract class BaseDecorator
|
||||||
|
{
|
||||||
|
public BaseDecorator() { }
|
||||||
|
|
||||||
|
public abstract boolean canDecorate(RoomData room);
|
||||||
|
|
||||||
|
public abstract boolean decorate(RoomData room, Random random, DDProperties properties);
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package StevenDimDoors.experimental.decorators;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import StevenDimDoors.experimental.RoomData;
|
||||||
|
|
||||||
|
public class DecoratorFinder
|
||||||
|
{
|
||||||
|
private static ArrayList<BaseDecorator> decorators = null;
|
||||||
|
|
||||||
|
private DecoratorFinder() { }
|
||||||
|
|
||||||
|
public static BaseDecorator find(RoomData room, Random random)
|
||||||
|
{
|
||||||
|
if (decorators == null)
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since there are only a few decorators right now, we just iterate
|
||||||
|
// over the list and check them all. If we add a lot, we'll need to
|
||||||
|
// switch to a more efficient approach.
|
||||||
|
ArrayList<BaseDecorator> matches = new ArrayList<BaseDecorator>();
|
||||||
|
for (BaseDecorator decorator : decorators)
|
||||||
|
{
|
||||||
|
if (decorator.canDecorate(room))
|
||||||
|
{
|
||||||
|
matches.add(decorator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matches.isEmpty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return matches.get( random.nextInt(matches.size()) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void load()
|
||||||
|
{
|
||||||
|
// List all the decorators we have
|
||||||
|
decorators = new ArrayList<BaseDecorator>();
|
||||||
|
decorators.add(new LinkDestinationDecorator());
|
||||||
|
decorators.add(new DefaultDoorDecorator());
|
||||||
|
decorators.add(new TorchDecorator());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package StevenDimDoors.experimental.decorators;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import StevenDimDoors.experimental.RoomData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||||
|
|
||||||
|
public class DefaultDoorDecorator extends BaseDecorator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDecorate(RoomData room) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean decorate(RoomData room, Random random,
|
||||||
|
DDProperties properties) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package StevenDimDoors.experimental.decorators;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import StevenDimDoors.experimental.RoomData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||||
|
|
||||||
|
|
||||||
|
public class LinkDestinationDecorator extends BaseDecorator
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean canDecorate(RoomData room) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean decorate(RoomData room, Random random,
|
||||||
|
DDProperties properties) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package StevenDimDoors.experimental.decorators;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import StevenDimDoors.experimental.RoomData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||||
|
|
||||||
|
public class TorchDecorator extends BaseDecorator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDecorate(RoomData room) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean decorate(RoomData room, Random random,
|
||||||
|
DDProperties properties) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user