diff --git a/src/main/java/StevenDimDoors/experimental/MazeBuilder.java b/src/main/java/StevenDimDoors/experimental/MazeBuilder.java index 760c399..592b2d0 100644 --- a/src/main/java/StevenDimDoors/experimental/MazeBuilder.java +++ b/src/main/java/StevenDimDoors/experimental/MazeBuilder.java @@ -8,12 +8,16 @@ import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; 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.config.DDProperties; 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 MazeBuilder() { } @@ -28,7 +32,7 @@ public class MazeBuilder buildRooms(design.getLayout(), world, offset); carveDoorways(design.getLayout(), 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); } @@ -117,9 +121,11 @@ public class MazeBuilder } } - private static void decorateRooms(DirectedGraph layout, World world, Point3D offset) + private static void decorateRooms(DirectedGraph layout, + World world, Point3D offset, Random random, DDProperties properties) { RoomData room; + BaseDecorator decorator; PartitionNode partition; ArrayList links = new ArrayList(); @@ -129,8 +135,16 @@ public class MazeBuilder room = node.data(); partition = room.getPartitionNode(); links.addAll(room.getOutboundLinks()); - - // TODO: Add decorator code here! + // Protected rooms must be decorated because they have links. + // 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 for (LinkPlan link : links) diff --git a/src/main/java/StevenDimDoors/experimental/decorators/BaseDecorator.java b/src/main/java/StevenDimDoors/experimental/decorators/BaseDecorator.java new file mode 100644 index 0000000..05bd70f --- /dev/null +++ b/src/main/java/StevenDimDoors/experimental/decorators/BaseDecorator.java @@ -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); +} diff --git a/src/main/java/StevenDimDoors/experimental/decorators/DecoratorFinder.java b/src/main/java/StevenDimDoors/experimental/decorators/DecoratorFinder.java new file mode 100644 index 0000000..ce925fe --- /dev/null +++ b/src/main/java/StevenDimDoors/experimental/decorators/DecoratorFinder.java @@ -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 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 matches = new ArrayList(); + 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(); + decorators.add(new LinkDestinationDecorator()); + decorators.add(new DefaultDoorDecorator()); + decorators.add(new TorchDecorator()); + } +} diff --git a/src/main/java/StevenDimDoors/experimental/decorators/DefaultDoorDecorator.java b/src/main/java/StevenDimDoors/experimental/decorators/DefaultDoorDecorator.java new file mode 100644 index 0000000..ffc4fa7 --- /dev/null +++ b/src/main/java/StevenDimDoors/experimental/decorators/DefaultDoorDecorator.java @@ -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; + } + +} diff --git a/src/main/java/StevenDimDoors/experimental/decorators/LinkDestinationDecorator.java b/src/main/java/StevenDimDoors/experimental/decorators/LinkDestinationDecorator.java new file mode 100644 index 0000000..17f5db4 --- /dev/null +++ b/src/main/java/StevenDimDoors/experimental/decorators/LinkDestinationDecorator.java @@ -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; + } +} diff --git a/src/main/java/StevenDimDoors/experimental/decorators/TorchDecorator.java b/src/main/java/StevenDimDoors/experimental/decorators/TorchDecorator.java new file mode 100644 index 0000000..6d736ac --- /dev/null +++ b/src/main/java/StevenDimDoors/experimental/decorators/TorchDecorator.java @@ -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; + } + +}