diff --git a/sources/codemetropolis-toolchain-commons/src/main/java/codemetropolis/toolchain/commons/cmxml/Point.java b/sources/codemetropolis-toolchain-commons/src/main/java/codemetropolis/toolchain/commons/cmxml/Point.java index dd3fa473..18c5ba78 100644 --- a/sources/codemetropolis-toolchain-commons/src/main/java/codemetropolis/toolchain/commons/cmxml/Point.java +++ b/sources/codemetropolis-toolchain-commons/src/main/java/codemetropolis/toolchain/commons/cmxml/Point.java @@ -48,5 +48,40 @@ public int getZ() { protected void setZ(int z) { this.z = z; } + + @Override + public String toString() { + return "Point [x=" + x + ", y=" + y + ", z=" + z + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + x; + result = prime * result + y; + result = prime * result + z; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Point other = (Point) obj; + if (x != other.x) + return false; + if (y != other.y) + return false; + if (z != other.z) + return false; + return true; + } + + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutor.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutor.java index fad5b7de..aacfb094 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutor.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutor.java @@ -15,45 +15,26 @@ import codemetropolis.toolchain.commons.util.Resources; import codemetropolis.toolchain.rendering.control.WorldBuilder; import codemetropolis.toolchain.rendering.events.ProgressEventListener; -import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; import codemetropolis.toolchain.rendering.exceptions.RenderingException; import codemetropolis.toolchain.rendering.exceptions.TooLongRenderDurationException; public class RenderingExecutor extends AbstractExecutor { - + protected File worldDir; + protected File tempDir; + @Override public boolean execute(ExecutorArgs args) { - RenderingExecutorArgs renderingArgs = (RenderingExecutorArgs)args; - - File worldDir = new File(renderingArgs.getWorldPath()); - File tempDir = new File(worldDir, "TEMP"); + RenderingExecutorArgs renderingArgs = (RenderingExecutorArgs) args; + + worldDir = new File(renderingArgs.getWorldPath()); + tempDir = new File(worldDir, "TEMP"); tempDir.deleteOnExit(); - boolean overwrite = renderingArgs.isSilentOverwriteEnabled(); - - if(worldDir.exists() && worldDir.isDirectory()) { - if(!overwrite) { - print(false, Resources.get("world_already_exists"), tempDir.getAbsolutePath()); - Scanner in = new Scanner(System.in); - String input = ""; - while(!input.equalsIgnoreCase("Y") && !input.equalsIgnoreCase("N")) { - input = in.next(); - } - in.close(); - if(input.equalsIgnoreCase("Y")) { - overwrite = true; - } else { - print(Resources.get("render_interrupted")); - return false; - } - } - if(overwrite) { - FileUtils.deleteDirectory(worldDir); - } - } - + + generateWorldDir(renderingArgs.isSilentOverwriteEnabled()); + try { boolean isValid = CmxmlValidator.validate(renderingArgs.getInputFile()); - if(!isValid) { + if (!isValid) { throw new CmxmlValidationFailedException(); } } catch (IOException e) { @@ -63,22 +44,22 @@ public boolean execute(ExecutorArgs args) { printError(e, Resources.get("invalid_input_xml_error")); return false; } - + WorldBuilder worldBuilder = new WorldBuilder(renderingArgs.getWorldPath()); - for(EventListener listener : listeners) { + for (EventListener listener : listeners) { worldBuilder.addEventListener((ProgressEventListener) listener); } - + print(Resources.get("rendering_reading_input")); try { worldBuilder.createBuildings(renderingArgs.getInputFile()); - } catch (BuildingTypeMismatchException e) { + } catch (Exception e) { printError(e, Resources.get("building_creation_failed_error")); return false; } print(Resources.get("rendering_reading_input_done")); print(Resources.get("buildables_found"), worldBuilder.getNumberOfBuildings()); - + print(Resources.get("creating_blocks")); try { worldBuilder.createBlocks(tempDir, renderingArgs.getMaxTime()); @@ -88,10 +69,10 @@ public boolean execute(ExecutorArgs args) { } long elapsed = worldBuilder.getTimeElapsedDuringLastPhase(); int hours = (int) (elapsed / (1000 * 60 * 60)); - int minutes = (int) (elapsed % (1000 * 60 * 60) / (1000 * 60)); - print(Resources.get("creating_blocks_done"), worldBuilder.getNumberOfBlocks(), hours, minutes); - - print(Resources.get("placing_blocks")); + int minutes = (int) (elapsed % (1000 * 60 * 60) / (1000 * 60)); + print(Resources.get("creating_blocks_done"), worldBuilder.getNumberOfBlocks(), hours, minutes); + + print(Resources.get("placing_blocks")); try { worldBuilder.build(tempDir); } catch (RenderingException e) { @@ -100,22 +81,59 @@ public boolean execute(ExecutorArgs args) { } elapsed = worldBuilder.getTimeElapsedDuringLastPhase(); hours = (int) (elapsed / (1000 * 60 * 60)); - minutes = (int) (elapsed % (1000 * 60 * 60) / (1000 * 60)); - print(Resources.get("placing_blocks_done"), hours, minutes); - - return true; + minutes = (int) (elapsed % (1000 * 60 * 60) / (1000 * 60)); + print(Resources.get("placing_blocks_done"), hours, minutes); + + return true; + } + + protected boolean generateWorldDir(boolean overwrite) { + if (worldDir.exists() && worldDir.isDirectory()) { + if (!overwrite) { + print(false, Resources.get("world_already_exists"), tempDir.getAbsolutePath()); + if (overridePermission()) { + FileUtils.deleteDirectory(worldDir); + } else { + print(Resources.get("render_interrupted")); + return false; + } + } + if (overwrite) { + FileUtils.deleteDirectory(worldDir); + } + } + return true; } - - //region PROGRESS EVENT + + public boolean overridePermission() { + + Scanner in = new Scanner(System.in); + String input = ""; + while (!input.equalsIgnoreCase("Y") && !input.equalsIgnoreCase("N")) { + input = in.next(); + } + in.close(); + if (input.equalsIgnoreCase("Y")) { + return true; + } else { + return false; + } + } + + // region PROGRESS EVENT private List listeners = new ArrayList(); - - public synchronized void addEventListener(ProgressEventListener listener) { + + public int getListenerCount() { + return listeners.size(); + } + + public synchronized void addEventListener(ProgressEventListener listener) { listeners.add(listener); } - - public synchronized void removeEventListener(ProgressEventListener listener) { + + public synchronized void removeEventListener(ProgressEventListener listener) { listeners.remove(listener); } - //endregion - + // endregion + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutorArgs.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutorArgs.java index d6b26410..a605fbc1 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutorArgs.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/RenderingExecutorArgs.java @@ -14,6 +14,7 @@ public RenderingExecutorArgs(String inputFile, String worldPath) { } public RenderingExecutorArgs(String inputFile, String worldPath, boolean overwriteSilently) { + this(inputFile, worldPath, overwriteSilently, Integer.MAX_VALUE); } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/control/WorldBuilder.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/control/WorldBuilder.java index c8b174c2..84fe58bd 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/control/WorldBuilder.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/control/WorldBuilder.java @@ -37,7 +37,7 @@ public WorldBuilder(String worldPath) { world = new World(worldPath, GROUND_LEVEL); } - public void createBuildings(String inputPath) throws BuildingTypeMismatchException{ + public void createBuildings(String inputPath) throws Exception{ BuildableTree buildables = new BuildableTree(); try { buildables.loadFromFile(inputPath); diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/BasicBlock.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/BasicBlock.java index dc71b59d..d34f21c7 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/BasicBlock.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/BasicBlock.java @@ -1,90 +1,85 @@ package codemetropolis.toolchain.rendering.model; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.util.Collections; import java.util.HashMap; import java.util.Map; -import codemetropolis.toolchain.rendering.RenderingExecutor; - public class BasicBlock { - public static final BasicBlock NonBlock; - public static final Map idToName; - public static final Map idToHumanReadableName; - public static final Map nameToId; - public static final Map humanReadableNameToId; - - static { - NonBlock = new BasicBlock((short)-1 ); - idToName = new HashMap(); - idToHumanReadableName = new HashMap(); - nameToId = new HashMap(); - humanReadableNameToId = new HashMap(); - - InputStream csvStream = RenderingExecutor.class.getClassLoader().getResourceAsStream("blocks.csv"); - try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(csvStream, "UTF-8"))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - String[] blockInfo = line.split(","); - idToName.put(Short.parseShort(blockInfo[0]), blockInfo[1]); - idToHumanReadableName.put(Short.parseShort(blockInfo[0]), blockInfo[2]); - nameToId.put(blockInfo[1], Short.parseShort(blockInfo[0])); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private short id; - private int data; - - public BasicBlock(short id) { - this(id, 0); - } + public static final BasicBlock NON_BLOCK = new BasicBlock(""); + + // Blocks + public static final BasicBlock AIR = new BasicBlock("minecraft:air"); + public static final BasicBlock STONE = new BasicBlock("minecraft:stone"); + public static final BasicBlock STONE_BRICKS = new BasicBlock("minecraft:stone_bricks"); + public static final BasicBlock SANDSTONE = new BasicBlock("minecraft:sandstone"); + public static final BasicBlock GRASS_BLOCK = new BasicBlock("minecraft:grass_block"); + public static final BasicBlock REDSTONE_BLOCK = new BasicBlock("minecraft:redstone_block"); + public static final BasicBlock REDSTONE_LAMP = new BasicBlock("minecraft:redstone_lamp", + new HashMap() { + { + put("lit", "true"); + } + }); + + // Items + public static final BasicBlock FENCE = new BasicBlock("minecraft:oak_fence"); + public static final BasicBlock TORCH = new BasicBlock("minecraft:wall_torch"); + public static final BasicBlock BANNER = new BasicBlock("minecraft:white_banner"); + public static final BasicBlock DOOR = new BasicBlock("minecraft:oak_door"); + public static final BasicBlock SIGN = new BasicBlock("minecraft:sign"); + public static final BasicBlock WALL_SIGN = new BasicBlock("minecraft:wall_sign"); + + // Plants + public static final BasicBlock POPPY = new BasicBlock("minecraft:poppy"); + public static final BasicBlock DANDELION = new BasicBlock("minecraft:dandelion"); + public static final BasicBlock BROWN_MUSHROOM = new BasicBlock("minecraft:brown_mushroom"); + public static final BasicBlock OAK_SAPLING = new BasicBlock("minecraft:oak_sapling"); + + // Wools + public static final BasicBlock RED_WOOL = new BasicBlock("minecraft:red_wool"); + public static final BasicBlock GREENWOOL = new BasicBlock("minecraft:green_wool"); + public static final BasicBlock BLUE_WOOL = new BasicBlock("minecraft:blue_wool"); + public static final BasicBlock YELLOW_WOOL = new BasicBlock("minecraft:yellow_wool"); + public static final BasicBlock MAGENTA_WOOL = new BasicBlock("minecraft:magenta_wool"); + public static final BasicBlock PURPLE_WOOL = new BasicBlock("minecraft:purple_wool"); + public static final BasicBlock BLACK_WOOL = new BasicBlock("minecraft:black_wool"); + + private String id; + private Map properties = Collections.emptyMap(); - public BasicBlock(short id, int data) { + public BasicBlock(String id) { this.id = id; - this.data = data; } - - public BasicBlock(String name) { - this(nameToId.get(name), 0); - } - - public BasicBlock(String name, int data) { - this(nameToId.get(name), data); + + public BasicBlock(String id, Map properties) { + this.id = id; + this.properties = properties; } - + public BasicBlock(BasicBlock original) { this.id = original.id; - this.data = original.data; + this.properties = new HashMap<>(original.properties); } - - public String getName() { - return idToName.get(id); + + public Map getProperties() { + return properties; } - - public String getHumanReadableName() { - return idToHumanReadableName.get(id); + + public void setProperties(Map properties) { + this.properties = properties; } - public short getId() { + public String getId() { return id; } - public int getData() { - return data; - } - @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + data; - result = prime * result + id; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); return result; } @@ -97,16 +92,22 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; BasicBlock other = (BasicBlock) obj; - if (data != other.data) + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) return false; - if (id != other.id) + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) return false; return true; } @Override public String toString() { - return getHumanReadableName() + (data != 0 ? data : ""); + return "BasicBlock [id=" + id + ", properties=" + properties + "]"; } - + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Building.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Building.java index 87e2f213..681e9463 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Building.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Building.java @@ -15,49 +15,42 @@ public class Building { protected LinkedList primitives = new LinkedList(); protected LinkedList signs = new LinkedList(); protected Buildable innerBuildable; - + protected Point position; protected Point center; protected Point size; - - public Building( Buildable innerBuildable ) - { + + public Building(Buildable innerBuildable) { this.innerBuildable = innerBuildable; - - size = new Point( - adjustSize(innerBuildable.getSizeX()), - adjustSize(innerBuildable.getSizeY()), - adjustSize(innerBuildable.getSizeZ()) - ); - - position = new Point( - innerBuildable.getPositionX(), - innerBuildable.getPositionY(), - innerBuildable.getPositionZ() - ); - - center = new Point( - (int)(size.getX() * 0.5), - (int)(size.getY() * 0.5), - (int)(size.getZ() * 0.5) - ); + + size = new Point(adjustSize(innerBuildable.getSizeX()), adjustSize(innerBuildable.getSizeY()), + adjustSize(innerBuildable.getSizeZ())); + + position = new Point(innerBuildable.getPositionX(), innerBuildable.getPositionY(), + innerBuildable.getPositionZ()); + + center = new Point((int) (size.getX() * 0.5), (int) (size.getY() * 0.5), (int) (size.getZ() * 0.5)); } - - private static int adjustSize( int x ) { - if(x < MIN_SIZE) return MIN_SIZE; - if(x % 2 == 0) return x + 1; + + public static int adjustSize(int x) { + if (x < MIN_SIZE) + return MIN_SIZE; + if (x % 2 == 0) + return x + 1; return x; } + + public int toCSVFile(File directory) { int count = 0; - for(Primitive primitive : primitives) { + for (Primitive primitive : primitives) { primitive.toCSVFile(directory); count += primitive.getNumberOfBlocks(); } return count; } - + public Buildable getInnerBuildable() { return innerBuildable; } @@ -76,9 +69,9 @@ public Point getSize() { public int getNumberOfBlocks() { int result = 0; - for(Primitive p : primitives) + for (Primitive p : primitives) result += p.getNumberOfBlocks(); return result; } - + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Cellar.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Cellar.java index 1da38d20..fda6e74b 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Cellar.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Cellar.java @@ -1,38 +1,43 @@ package codemetropolis.toolchain.rendering.model.building; +import java.util.LinkedList; + import codemetropolis.toolchain.commons.cmxml.Buildable; import codemetropolis.toolchain.commons.cmxml.Buildable.Type; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; import codemetropolis.toolchain.rendering.model.BasicBlock; import codemetropolis.toolchain.rendering.model.pattern.RepeationPattern; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; import codemetropolis.toolchain.rendering.model.primitive.SolidBox; import codemetropolis.toolchain.rendering.util.Orientation; public class Cellar extends Floor { - public Cellar(Buildable innerBuildable) throws BuildingTypeMismatchException { + public Cellar(Buildable innerBuildable) throws Exception { super(innerBuildable); - - if ( innerBuildable.getType() != Type.CELLAR ) + + if (innerBuildable.getType() != Type.CELLAR) { throw new BuildingTypeMismatchException(innerBuildable.getType(), getClass()); - - primitives.add( - 0, - new SolidBox( - position.translate( new Point( 1, 1, 1 ) ), - size.translate( new Point( -2, -2, -2 ) ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air" ) } } } ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air" ) } } } ), - Orientation.NearX ) ); - - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 3, size.getY() + 1, center.getZ() - 3 ) ), - new Point( 7, 1, 7 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air" ) } } } ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air" ) } } } ), - Orientation.NearX ) ); + } + + primitives.addAll(makePrimitives()); + + } + + public LinkedList makePrimitives() { + LinkedList primitive = new LinkedList<>(); + + primitive.add(0, + new SolidBox(position.translate(new Point(1, 1, 1)), size.translate(new Point(-2, -2, -2)), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), Orientation.NearX)); + + primitive.add(new SolidBox(position.translate(new Point(center.getX() - 3, size.getY() + 1, center.getZ() - 3)), + new Point(7, 1, 7), new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), Orientation.NearX)); + + return primitive; } } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Floor.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Floor.java index ced4a538..308afee8 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Floor.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Floor.java @@ -1,344 +1,252 @@ package codemetropolis.toolchain.rendering.model.building; +import java.util.LinkedList; + import codemetropolis.toolchain.commons.cmxml.Buildable; import codemetropolis.toolchain.commons.cmxml.Buildable.Type; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; import codemetropolis.toolchain.rendering.model.BasicBlock; +import codemetropolis.toolchain.rendering.model.pattern.Pattern; import codemetropolis.toolchain.rendering.model.pattern.RandomPattern; import codemetropolis.toolchain.rendering.model.pattern.RepeationPattern; import codemetropolis.toolchain.rendering.model.primitive.Door; import codemetropolis.toolchain.rendering.model.primitive.EmptyBox; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; import codemetropolis.toolchain.rendering.model.primitive.Row; +import codemetropolis.toolchain.rendering.model.primitive.Row.BlockFacing; import codemetropolis.toolchain.rendering.model.primitive.SolidBox; import codemetropolis.toolchain.rendering.model.primitive.WallSign; -import codemetropolis.toolchain.rendering.util.Character; import codemetropolis.toolchain.rendering.util.Orientation; public class Floor extends Building { - public Floor(Buildable innerBuildable) throws BuildingTypeMismatchException { + public Floor(Buildable innerBuildable) throws Exception { super(innerBuildable); - - if ( innerBuildable.getType()!= Type.FLOOR && innerBuildable.getType() != Type.CELLAR ) + + if (innerBuildable.getType() != Type.FLOOR && innerBuildable.getType() != Type.CELLAR) throw new BuildingTypeMismatchException(innerBuildable.getType(), getClass()); - prepareWalls(); - prepareStairs(); - prepareDoor(); - prepareSigns(); - prepareTorches(); + primitives.addAll(prepareWalls()); + primitives.addAll(prepareStairs()); + primitives.addAll(prepareDoor()); + primitives.addAll(prepareSigns()); + primitives.addAll(prepareTorches()); } - - protected void prepareDoor() { - BasicBlock _red = new BasicBlock( "minecraft:redstone_block" ); - BasicBlock _lgt = new BasicBlock( "minecraft:lit_redstone_lamp" ); - BasicBlock _rwl = new BasicBlock( "minecraft:wool", 14 ); - BasicBlock _gwl = new BasicBlock( "minecraft:wool", 5 ); - BasicBlock _bwl = new BasicBlock( "minecraft:wool", 3 ); - BasicBlock _ywl = new BasicBlock( "minecraft:wool", 4 ); - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 1, 0, 0 ) ), new Point( 3, 4, 1 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _rwl }, - { _lgt }, - { _red }, - { _rwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 1, 0, size.getZ() - 1 ) ), new Point( 3, 4, 1 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _gwl }, - { _lgt }, - { _red }, - { _gwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( 0, 0, center.getZ()-1 ) ), new Point( 1, 4, 3 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _bwl }, - { _lgt }, - { _red }, - { _bwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( size.getX()-1, 0, center.getZ() - 1 ) ), new Point( 1, 4, 3 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _ywl }, - { _lgt }, - { _red }, - { _ywl } - } - } ), - Orientation.NearX ) - ); - - primitives.add(new Door(position.getX() + size.getX() / 2, position.getY() + 1, position.getZ(), Door.Orientation.SOUTH)); - primitives.add(new Door(position.getX() + size.getX() / 2, position.getY() + 1, position.getZ() + size.getZ() - 1, Door.Orientation.NORTH)); - primitives.add(new Door(position.getX(), position.getY() + 1, position.getZ() + size.getZ() / 2, Door.Orientation.EAST)); - primitives.add(new Door(position.getX() + size.getX() - 1, position.getY() + 1, position.getZ() + size.getZ() / 2, Door.Orientation.WEST)); + + protected LinkedList prepareDoor() { + LinkedList doors = new LinkedList<>(); + + doors.add(new SolidBox(position.translate(new Point(center.getX() - 1, 0, 0)), new Point(3, 4, 1), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.RED_WOOL }, { BasicBlock.REDSTONE_LAMP }, + { BasicBlock.REDSTONE_BLOCK }, { BasicBlock.RED_WOOL } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(center.getX() - 1, 0, size.getZ() - 1)), new Point(3, 4, 1), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.GREENWOOL }, { BasicBlock.REDSTONE_LAMP }, + { BasicBlock.REDSTONE_BLOCK }, { BasicBlock.GREENWOOL } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(0, 0, center.getZ() - 1)), new Point(1, 4, 3), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.BLUE_WOOL }, { BasicBlock.REDSTONE_LAMP }, + { BasicBlock.REDSTONE_BLOCK }, { BasicBlock.BLUE_WOOL } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(size.getX() - 1, 0, center.getZ() - 1)), new Point(1, 4, 3), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.YELLOW_WOOL }, { BasicBlock.REDSTONE_LAMP }, + { BasicBlock.REDSTONE_BLOCK }, { BasicBlock.YELLOW_WOOL } } }), + Orientation.NearX)); + + doors.add(new Door(position.getX() + size.getX() / 2, position.getY() + 1, position.getZ(), + Door.Orientation.SOUTH)); + doors.add(new Door(position.getX() + size.getX() / 2, position.getY() + 1, position.getZ() + size.getZ() - 1, + Door.Orientation.NORTH)); + doors.add(new Door(position.getX(), position.getY() + 1, position.getZ() + size.getZ() / 2, + Door.Orientation.EAST)); + doors.add(new Door(position.getX() + size.getX() - 1, position.getY() + 1, position.getZ() + size.getZ() / 2, + Door.Orientation.WEST)); + + return doors; } - - protected void prepareStairs() { - BasicBlock _air = new BasicBlock( (short) 0 ); - BasicBlock _str = new BasicBlock( (short) 1 ); - BasicBlock _cre = new BasicBlock( (short) 85 ); - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 2, 0, center.getZ() - 2 ) ), - new Point( 5, size.getY() + 1, 5 ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _air, _air, _air, _air, _air }, - { _air, _str, _air, _air, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _str, _air, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _str, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _cre, _str, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _air, _air, _str, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _air, _str, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _cre, _air, _air }, - { _air, _str, _air, _air, _air }, - { _air, _air, _air, _air, _air } - }, - { - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _str, _cre, _air, _air }, - { _air, _air, _air, _air, _air }, - { _air, _air, _air, _air, _air } - } - } ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:fence" ) } } } ), - Orientation.NearY ) ); + + protected LinkedList prepareStairs() { + + LinkedList stairs = new LinkedList<>(); + + stairs.add(new SolidBox(position.translate(new Point(center.getX() - 2, 0, center.getZ() - 2)), + new Point(5, size.getY() + 1, 5), getStairRepetationPattern(), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.FENCE } } }), Orientation.NearY)); + return stairs; } - - protected void prepareWalls() { + + protected Pattern getStairRepetationPattern() { + BasicBlock _air = BasicBlock.AIR; + BasicBlock _str = BasicBlock.STONE; + BasicBlock _cre = BasicBlock.FENCE; + + return new RepeationPattern(new BasicBlock[][][] { + { { _air, _air, _air, _air, _air }, { _air, _str, _air, _air, _air }, { _air, _air, _cre, _air, _air }, + { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _str, _air, _air }, { _air, _air, _cre, _air, _air }, + { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _str, _air }, { _air, _air, _cre, _air, _air }, + { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air }, { _air, _air, _cre, _str, _air }, + { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air }, { _air, _air, _cre, _air, _air }, + { _air, _air, _air, _str, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air }, { _air, _air, _cre, _air, _air }, + { _air, _air, _str, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air }, { _air, _air, _cre, _air, _air }, + { _air, _str, _air, _air, _air }, { _air, _air, _air, _air, _air } }, + { { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air }, { _air, _str, _cre, _air, _air }, + { _air, _air, _air, _air, _air }, { _air, _air, _air, _air, _air } } }); + } + + protected LinkedList prepareWalls() throws Exception { RepeationPattern _bottomFill; RepeationPattern _topFill; RandomPattern _sideFill; RepeationPattern _stroke; BasicBlock _sideBlock; BasicBlock _strcBlock; - - if(innerBuildable.hasAttribute( "character" )) - { - Character character = Character.parse(innerBuildable.getAttributeValue("character")); - _sideBlock = character.getBlock(); - _topFill = new RepeationPattern( new BasicBlock[][][] { { { character.getTopBlock() } } } ); + LinkedList walls = new LinkedList<>(); + + if (innerBuildable.hasAttribute("character")) { + _sideBlock = new BasicBlock(innerBuildable.getAttributeValue("character")); + _topFill = new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.FENCE } } }); } else { - _sideBlock = new BasicBlock( "minecraft:wool", 2 ); - _topFill = new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:wool", 2 ) } } } ); + _sideBlock = BasicBlock.MAGENTA_WOOL; + _topFill = new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.MAGENTA_WOOL } } }); } - - if(innerBuildable.hasAttribute( "external_character" )) - { - Character externalCharacter = Character.parse(innerBuildable.getAttributeValue("external_character")); - _bottomFill = new RepeationPattern( new BasicBlock[][][] { { { externalCharacter.getBlock() } } } ); - _strcBlock = externalCharacter.getBlock(); - _stroke = new RepeationPattern( new BasicBlock[][][] { { { externalCharacter.getBlock() } } } ); + + if (innerBuildable.hasAttribute("external_character")) { + BasicBlock block = new BasicBlock(innerBuildable.getAttributeValue("external_character")); + _bottomFill = new RepeationPattern(new BasicBlock[][][] { { { block } } }); + _strcBlock = block; + _stroke = new RepeationPattern(new BasicBlock[][][] { { { block } } }); } else { - _bottomFill = new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:wool", 2 ) } } } ); - _strcBlock = new BasicBlock( "minecraft:wool", 10 ); - _stroke = new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:wool", 15 ) } } } ); + _bottomFill = new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.MAGENTA_WOOL } } }); + _strcBlock = BasicBlock.PURPLE_WOOL; + _stroke = new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.BLACK_WOOL } } }); } - - RandomPattern _fallbackPattern = new RandomPattern( new RepeationPattern( new BasicBlock[][][] { { { BasicBlock.NonBlock } } } ) ); - _fallbackPattern.add( new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:fence" ) } } } ), .5 ); - _sideFill = new RandomPattern( _fallbackPattern ); + + RandomPattern _fallbackPattern = new RandomPattern( + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.NON_BLOCK } } })); + _fallbackPattern.add(new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.FENCE } } }), .5); + _sideFill = new RandomPattern(_fallbackPattern); _sideFill.add( - new RepeationPattern( - new BasicBlock[][][] - { - { - { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, - { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, - { _strcBlock, _strcBlock, _strcBlock, _strcBlock, _strcBlock }, - { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, - { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock } - } - } ), - innerBuildable.hasAttribute( "completeness" ) - ? Double.parseDouble( innerBuildable.getAttributeValue("completeness") ) - : 1 ); - primitives.add( - new EmptyBox( - position, - size, - _bottomFill, - _topFill, - _sideFill, - _stroke, - new Point( 1, 1, 1 ), - new Point( 1, 1, 1 ) ) - ); + new RepeationPattern( + new BasicBlock[][][] { { { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, + { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, + { _strcBlock, _strcBlock, _strcBlock, _strcBlock, _strcBlock }, + { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock }, + { _sideBlock, _sideBlock, _strcBlock, _sideBlock, _sideBlock } } }), + innerBuildable.hasAttribute("completeness") + ? Double.parseDouble(innerBuildable.getAttributeValue("completeness")) + : 1); + walls.add(new EmptyBox(position, size, _bottomFill, _topFill, _sideFill, _stroke, new Point(1, 1, 1), + new Point(1, 1, 1))); + return walls; } - - private void prepareSigns( ) { - //Wall signs outside - primitives.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() - 1, WallSign.Orientation.NORTH, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() + size.getZ(), WallSign.Orientation.SOUTH, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() - 1, position.getY() + 3, position.getZ() + size.getZ() / 2, WallSign.Orientation.WEST, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() + size.getX(), position.getY() + 3, position.getZ() + size.getZ() / 2, WallSign.Orientation.EAST, innerBuildable.getName())); - //Wall signs inside - primitives.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() + 1, WallSign.Orientation.SOUTH, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() + size.getZ() - 2, WallSign.Orientation.NORTH, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() + 1, position.getY() + 3, position.getZ() + size.getZ() / 2, WallSign.Orientation.EAST, innerBuildable.getName())); - primitives.add(new WallSign(position.getX() + size.getX() - 2, position.getY() + 3, position.getZ() + size.getZ() / 2, WallSign.Orientation.WEST, innerBuildable.getName())); + + protected LinkedList prepareSigns() { + LinkedList signs = new LinkedList<>(); + + // Wall signs outside + signs.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() - 1, + WallSign.Orientation.NORTH, innerBuildable.getName())); + signs.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() + size.getZ(), + WallSign.Orientation.SOUTH, innerBuildable.getName())); + signs.add(new WallSign(position.getX() - 1, position.getY() + 3, position.getZ() + size.getZ() / 2, + WallSign.Orientation.WEST, innerBuildable.getName())); + signs.add(new WallSign(position.getX() + size.getX(), position.getY() + 3, position.getZ() + size.getZ() / 2, + WallSign.Orientation.EAST, innerBuildable.getName())); + // Wall signs inside + signs.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, position.getZ() + 1, + WallSign.Orientation.SOUTH, innerBuildable.getName())); + signs.add(new WallSign(position.getX() + size.getX() / 2, position.getY() + 3, + position.getZ() + size.getZ() - 2, WallSign.Orientation.NORTH, innerBuildable.getName())); + signs.add(new WallSign(position.getX() + 1, position.getY() + 3, position.getZ() + size.getZ() / 2, + WallSign.Orientation.EAST, innerBuildable.getName())); + signs.add(new WallSign(position.getX() + size.getX() - 2, position.getY() + 3, + position.getZ() + size.getZ() / 2, WallSign.Orientation.WEST, innerBuildable.getName())); + return signs; } - - private void prepareTorches( ) { - - if(!innerBuildable.hasAttribute( "torches" )) return; - + + private LinkedList prepareTorches() { + LinkedList torches = new LinkedList<>(); + + if (!innerBuildable.hasAttribute("torches")) + return torches; + int numberOfTorches = Integer.parseInt(innerBuildable.getAttributeValue("torches")); BasicBlock[] pattern; - + pattern = createTorchPattern(numberOfTorches, 3); - primitives.add(new Row( - new Point(position.getX() + size.getX() / 2 + 2, position.getY() + 2, position.getZ() + 1), - size.getX() / 2 - 2, - Row.Direction.WEST, - pattern)); - - primitives.add(new Row( - new Point(position.getX() + size.getX() / 2 - 2, position.getY() + 2, position.getZ() + 1), - size.getX() / 2 - 2, - Row.Direction.EAST, - pattern)); - + torches.add(new Row(new Point(position.getX() + size.getX() / 2 + 2, position.getY() + 2, position.getZ() + 1), + size.getX() / 2 - 2, Row.Direction.WEST, pattern, BlockFacing.SOUTH)); + + torches.add(new Row(new Point(position.getX() + size.getX() / 2 - 2, position.getY() + 2, position.getZ() + 1), + size.getX() / 2 - 2, Row.Direction.EAST, pattern, BlockFacing.SOUTH)); + pattern = createTorchPattern(numberOfTorches, 4); - primitives.add(new Row( - new Point(position.getX() + size.getX() / 2 + 2, position.getY() + 2, position.getZ() + size.getZ() - 2), - size.getX() / 2 - 2, - Row.Direction.WEST, - pattern)); - - primitives.add(new Row( - new Point(position.getX() + size.getX() / 2 - 2, position.getY() + 2, position.getZ() + size.getZ() - 2), - size.getX() / 2 - 2, - Row.Direction.EAST, - pattern)); - + torches.add(new Row( + new Point(position.getX() + size.getX() / 2 + 2, position.getY() + 2, + position.getZ() + size.getZ() - 2), + size.getX() / 2 - 2, Row.Direction.WEST, pattern, BlockFacing.NORTH)); + + torches.add(new Row( + new Point(position.getX() + size.getX() / 2 - 2, position.getY() + 2, + position.getZ() + size.getZ() - 2), + size.getX() / 2 - 2, Row.Direction.EAST, pattern, BlockFacing.NORTH)); + pattern = createTorchPattern(numberOfTorches, 1); - primitives.add(new Row( - new Point(position.getX() + 1, position.getY() + 2, position.getZ() + size.getZ() / 2 + 2), - size.getZ() / 2 - 2, - Row.Direction.NORTH, - pattern)); - - primitives.add(new Row( - new Point(position.getX() + 1, position.getY() + 2, position.getZ() + size.getZ() / 2 - 2), - size.getZ() / 2 - 2, - Row.Direction.SOUTH, - pattern)); - + torches.add(new Row(new Point(position.getX() + 1, position.getY() + 2, position.getZ() + size.getZ() / 2 + 2), + size.getZ() / 2 - 2, Row.Direction.NORTH, pattern, BlockFacing.EAST)); + + torches.add(new Row(new Point(position.getX() + 1, position.getY() + 2, position.getZ() + size.getZ() / 2 - 2), + size.getZ() / 2 - 2, Row.Direction.SOUTH, pattern, BlockFacing.EAST)); + pattern = createTorchPattern(numberOfTorches, 2); - primitives.add(new Row( - new Point(position.getX() + size.getX() - 2, position.getY() + 2, position.getZ() + size.getZ() / 2 + 2), - size.getZ() / 2 - 2, - Row.Direction.NORTH, - pattern)); - - primitives.add(new Row( - new Point(position.getX() + size.getX() - 2, position.getY() + 2, position.getZ() + size.getZ() / 2 - 2), - size.getZ() / 2 - 2, - Row.Direction.SOUTH, - pattern)); - + torches.add(new Row( + new Point(position.getX() + size.getX() - 2, position.getY() + 2, + position.getZ() + size.getZ() / 2 + 2), + size.getZ() / 2 - 2, Row.Direction.NORTH, pattern, BlockFacing.WEST)); + + torches.add(new Row( + new Point(position.getX() + size.getX() - 2, position.getY() + 2, + position.getZ() + size.getZ() / 2 - 2), + size.getZ() / 2 - 2, Row.Direction.SOUTH, pattern, BlockFacing.WEST)); + + return torches; } - - private BasicBlock[] createTorchPattern(int number, int data) { + + protected BasicBlock[] createTorchPattern(int number, int data) { BasicBlock[] pattern = null; - BasicBlock torch = new BasicBlock((short) 50, data); - BasicBlock space = BasicBlock.NonBlock; - - switch(number) { - case 0: - pattern = new BasicBlock[] { space }; - break; - case 1: - pattern = new BasicBlock[] { torch, space, space, space, space }; - break; - case 2: - pattern = new BasicBlock[] { torch, space, space, space }; - break; - case 3: - pattern = new BasicBlock[] { torch, space, space }; - break; - case 4: - pattern = new BasicBlock[] { torch, space }; - break; - case 5: - pattern = new BasicBlock[] { torch }; - break; + BasicBlock torch = BasicBlock.TORCH; + BasicBlock space = BasicBlock.NON_BLOCK; + + switch (number) { + case 0: + pattern = new BasicBlock[] { space }; + break; + case 1: + pattern = new BasicBlock[] { torch, space, space, space, space }; + break; + case 2: + pattern = new BasicBlock[] { torch, space, space, space }; + break; + case 3: + pattern = new BasicBlock[] { torch, space, space }; + break; + case 4: + pattern = new BasicBlock[] { torch, space }; + break; + case 5: + pattern = new BasicBlock[] { torch }; + break; } return pattern; } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Garden.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Garden.java index 88b163b9..5993a147 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Garden.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Garden.java @@ -1,5 +1,7 @@ package codemetropolis.toolchain.rendering.model.building; +import java.util.LinkedList; + import codemetropolis.toolchain.commons.cmxml.Buildable; import codemetropolis.toolchain.commons.cmxml.Buildable.Type; import codemetropolis.toolchain.commons.cmxml.Point; @@ -8,6 +10,7 @@ import codemetropolis.toolchain.rendering.model.pattern.RandomPattern; import codemetropolis.toolchain.rendering.model.pattern.RepeationPattern; import codemetropolis.toolchain.rendering.model.pattern.YSplitPattern; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; import codemetropolis.toolchain.rendering.model.primitive.SignPost; import codemetropolis.toolchain.rendering.model.primitive.SolidBox; import codemetropolis.toolchain.rendering.util.Orientation; @@ -16,133 +19,92 @@ public class Garden extends Building { public Garden(Buildable innerBuildable) throws BuildingTypeMismatchException { super(innerBuildable); - - if ( innerBuildable.getType() != Type.GARDEN ) + + if (innerBuildable.getType() != Type.GARDEN) throw new BuildingTypeMismatchException(innerBuildable.getType(), getClass()); - prepareBase(); - prepareDoor(); - prepareSigns(); + primitives.addAll(prepareBase()); + primitives.addAll(prepareDoor()); + primitives.addAll(prepareSigns()); + } - - private void prepareBase( ) { - BasicBlock _fnc = new BasicBlock( "minecraft:fence" ); - BasicBlock _sns = new BasicBlock( "minecraft:sandstone" ); - RandomPattern _flowers = new RandomPattern( new RepeationPattern( new BasicBlock[][][]{ { { BasicBlock.NonBlock } } } ) ); - - RandomPattern _redOrYellow = new RandomPattern( new RepeationPattern( new BasicBlock[][][]{ { { new BasicBlock( "minecraft:yellow_flower" ) } } } ) ); - _redOrYellow.add(new RepeationPattern( new BasicBlock[][][]{ { { new BasicBlock( "minecraft:red_flower" ) } } } ), 0.5); - _flowers.add( - _redOrYellow, - innerBuildable.hasAttribute( "flower-ratio" ) - ? Double.parseDouble( innerBuildable.getAttributeValue("flower-ratio") ) - : 0 ); - _flowers.add( - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:brown_mushroom" ) } } } ), - innerBuildable.hasAttribute( "mushroom-ratio" ) - ? Double.parseDouble( innerBuildable.getAttributeValue("mushroom-ratio") ) - : 0 ); - _flowers.add( - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:sapling" ) } } } ), - innerBuildable.hasAttribute( "tree-ratio" ) - ? Double.parseDouble( innerBuildable.getAttributeValue("tree-ratio") ) - : 0 ); - primitives.add( - new SolidBox( - position, new Point( size.getX(), 2, size.getZ() ), - new YSplitPattern( - 0, - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:grass" ) } } } ), - _flowers ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _fnc }, - { _sns } - } - } ), - Orientation.NearX ) ); + + + protected LinkedList prepareBase() { + BasicBlock _fnc = BasicBlock.FENCE; + BasicBlock _sns = BasicBlock.SANDSTONE; + LinkedList repeatPattern = new LinkedList<>(); + + RandomPattern _flowers = new RandomPattern( + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.NON_BLOCK } } })); + + RandomPattern _redOrYellow = new RandomPattern( + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.DANDELION } } })); + _redOrYellow.add(new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.POPPY } } }), 0.5); + _flowers.add(_redOrYellow, + innerBuildable.hasAttribute("flower-ratio") + ? Double.parseDouble(innerBuildable.getAttributeValue("flower-ratio")) + : 0); + _flowers.add(new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.BROWN_MUSHROOM } } }), + innerBuildable.hasAttribute("mushroom-ratio") + ? Double.parseDouble(innerBuildable.getAttributeValue("mushroom-ratio")) + : 0); + _flowers.add(new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.OAK_SAPLING } } }), + innerBuildable.hasAttribute("tree-ratio") + ? Double.parseDouble(innerBuildable.getAttributeValue("tree-ratio")) + : 0); + repeatPattern.add(new SolidBox(position, new Point(size.getX(), 2, size.getZ()), + new YSplitPattern(0, new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.GRASS_BLOCK } } }), + _flowers), + new RepeationPattern(new BasicBlock[][][] { { { _fnc }, { _sns } } }), Orientation.NearX)); + + return repeatPattern; + + } - - protected void prepareDoor( ) - { - BasicBlock _fnc = new BasicBlock( "minecraft:fence" ); - BasicBlock _rwl = new BasicBlock( "minecraft:wool", 14 ); - BasicBlock _gwl = new BasicBlock( "minecraft:wool", 5 ); - BasicBlock _bwl = new BasicBlock( "minecraft:wool", 3 ); - BasicBlock _ywl = new BasicBlock( "minecraft:wool", 4 ); - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 1, 0, 0 ) ), new Point( 3, 4, 1 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _fnc }, - { _fnc }, - { _fnc }, - { _rwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( center.getX() - 1, 0, size.getZ() - 1 ) ), new Point( 3, 4, 1 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _fnc }, - { _fnc }, - { _fnc }, - { _gwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( 0, 0, center.getZ()-1 ) ), new Point( 1, 4, 3 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _fnc }, - { _fnc }, - { _fnc }, - { _bwl } - } - } ), - Orientation.NearX ) - ); - primitives.add( - new SolidBox( - position.translate( new Point( size.getX()-1, 0, center.getZ() - 1 ) ), new Point( 1, 4, 3 ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:air", 2 ) } } } ), - new RepeationPattern( - new BasicBlock[][][] - { - { - { _fnc }, - { _fnc }, - { _fnc }, - { _ywl } - } - } ), - Orientation.NearX ) - ); + + protected LinkedList prepareDoor() { + + LinkedList doors = new LinkedList<>(); + + BasicBlock _fnc = BasicBlock.FENCE; + BasicBlock _rwl = BasicBlock.RED_WOOL; + BasicBlock _gwl = BasicBlock.GREENWOOL; + BasicBlock _bwl = BasicBlock.BLUE_WOOL; + BasicBlock _ywl = BasicBlock.YELLOW_WOOL; + doors.add(new SolidBox(position.translate(new Point(center.getX() - 1, 0, 0)), new Point(3, 4, 1), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { _fnc }, { _fnc }, { _fnc }, { _rwl } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(center.getX() - 1, 0, size.getZ() - 1)), new Point(3, 4, 1), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { _fnc }, { _fnc }, { _fnc }, { _gwl } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(0, 0, center.getZ() - 1)), new Point(1, 4, 3), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { _fnc }, { _fnc }, { _fnc }, { _bwl } } }), + Orientation.NearX)); + doors.add(new SolidBox(position.translate(new Point(size.getX() - 1, 0, center.getZ() - 1)), new Point(1, 4, 3), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.AIR } } }), + new RepeationPattern(new BasicBlock[][][] { { { _fnc }, { _fnc }, { _fnc }, { _ywl } } }), + Orientation.NearX)); + + return doors; } - - private void prepareSigns( ) { - primitives.add(new SignPost(position.getX(), position.getY() + 2, position.getZ(), SignPost.Orientation.NORTHWEST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 2, position.getZ(), SignPost.Orientation.NORTHEAST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX(), position.getY() + 2, position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHWEST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 2, position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHEAST, innerBuildable.getName())); + + protected LinkedList prepareSigns() { + LinkedList signs = new LinkedList<>(); + + signs.add(new SignPost(position.getX(), position.getY() + 2, position.getZ(), SignPost.Orientation.NORTHWEST, + innerBuildable.getName())); + signs.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 2, position.getZ(), + SignPost.Orientation.NORTHEAST, innerBuildable.getName())); + signs.add(new SignPost(position.getX(), position.getY() + 2, position.getZ() + size.getZ() - 1, + SignPost.Orientation.SOUTHWEST, innerBuildable.getName())); + signs.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 2, + position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHEAST, innerBuildable.getName())); + + return signs; } } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Ground.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Ground.java index b7f24d6f..5943ecfd 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Ground.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/building/Ground.java @@ -1,11 +1,14 @@ package codemetropolis.toolchain.rendering.model.building; +import java.util.LinkedList; + import codemetropolis.toolchain.commons.cmxml.Buildable; import codemetropolis.toolchain.commons.cmxml.Buildable.Type; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; import codemetropolis.toolchain.rendering.model.BasicBlock; import codemetropolis.toolchain.rendering.model.pattern.RepeationPattern; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; import codemetropolis.toolchain.rendering.model.primitive.SignPost; import codemetropolis.toolchain.rendering.model.primitive.SolidBox; import codemetropolis.toolchain.rendering.util.Orientation; @@ -15,28 +18,36 @@ public class Ground extends Building { public Ground(Buildable innerBuildable) throws BuildingTypeMismatchException { super(innerBuildable); - if ( innerBuildable.getType() != Type.GROUND ) + if (innerBuildable.getType() != Type.GROUND) throw new BuildingTypeMismatchException(innerBuildable.getType(), getClass()); - prepareBase(); - prepareSigns(); + primitives.addAll(prepareBase()); + primitives.addAll(prepareSigns()); } - - private void prepareBase( ) { - primitives.add( - new SolidBox( - position, - new Point( size.getX(), 1, size.getZ() ), - new RepeationPattern( new BasicBlock[][][]{ { { new BasicBlock( "minecraft:stone" ) } } } ), - new RepeationPattern( new BasicBlock[][][] { { { new BasicBlock( "minecraft:stonebrick" ) } } } ), - Orientation.NearX ) ); + + + protected LinkedList prepareBase() { + + LinkedList base = new LinkedList<>(); + base.add(new SolidBox(position, new Point(size.getX(), 1, size.getZ()), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.STONE } } }), + new RepeationPattern(new BasicBlock[][][] { { { BasicBlock.STONE_BRICKS } } }), Orientation.NearX)); + return base; } - - private void prepareSigns( ) { - primitives.add(new SignPost(position.getX(), position.getY() + 1, position.getZ(), SignPost.Orientation.NORTHWEST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 1, position.getZ(), SignPost.Orientation.NORTHEAST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX(), position.getY() + 1, position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHWEST, innerBuildable.getName())); - primitives.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 1, position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHEAST, innerBuildable.getName())); + + protected LinkedList prepareSigns() { + LinkedList signs = new LinkedList<>(); + + signs.add(new SignPost(position.getX(), position.getY() + 1, position.getZ(), SignPost.Orientation.NORTHWEST, + innerBuildable.getName())); + signs.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 1, position.getZ(), + SignPost.Orientation.NORTHEAST, innerBuildable.getName())); + signs.add(new SignPost(position.getX(), position.getY() + 1, position.getZ() + size.getZ() - 1, + SignPost.Orientation.SOUTHWEST, innerBuildable.getName())); + signs.add(new SignPost(position.getX() + size.getX() - 1, position.getY() + 1, + position.getZ() + size.getZ() - 1, SignPost.Orientation.SOUTHEAST, innerBuildable.getName())); + return signs; + } } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Banner.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Banner.java index f2a1dd13..e196e6e7 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Banner.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Banner.java @@ -1,52 +1,52 @@ package codemetropolis.toolchain.rendering.model.primitive; import java.io.File; +import java.util.HashMap; +import java.util.Map; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; public class Banner implements Primitive { - + public enum Orientation { - SOUTH(0), - SOUTHWEST(2), - WEST(4), - NORTHWEST(6), - NORTH(8), - NORTHEAST(10), - EAST(12), - SOUTHEAST(14); - + SOUTH(0), SOUTHWEST(2), WEST(4), NORTHWEST(6), NORTH(8), NORTHEAST(10), EAST(12), SOUTHEAST(14); + private final int value; - + Orientation(int v) { value = v; } - + public int getValue() { return value; } } - + private Point position; private Orientation orientation; - private String color; public Banner(int x, int y, int z, Orientation orientation, String color) { super(); this.position = new Point(x, y, z); this.orientation = orientation; - this.color = color; } - + @Override public int toCSVFile(File directory) { - new Boxel(new BasicBlock((short) 176, orientation.getValue()), position, color).toCSVFile(directory); + + Map properties = new HashMap<>(); + properties.put("facing", orientation.getValue() + ""); + + BasicBlock banner = new BasicBlock(BasicBlock.BANNER.getId(), properties); + + new Boxel(banner, position).toCSVFile(directory); return 1; } + @Override public int getNumberOfBlocks() { return 1; } - + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Boxel.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Boxel.java index 931fff2c..97a05c7c 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Boxel.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Boxel.java @@ -6,78 +6,96 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; import codemetropolis.blockmodifier.World; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; public class Boxel implements Primitive { - + public BasicBlock block; public Point position; public String info; - + public Boxel(BasicBlock block, Point position) { super(); this.block = block; this.position = position; } - + public Boxel(BasicBlock block, Point position, String info) { this(block, position); this.info = info; + } - + public void render(World world) { - if(position.getY() < 0 || position.getY() >= 255) return; - - switch(block.getId()) { - case 63: - world.setSignPost(position.getX(), position.getY(), position.getZ(), block.getData(), info); - break; - case 68: - world.setWallSign(position.getX(), position.getY(), position.getZ(), block.getData(), info); - break; - case 176: - world.setBanner(position.getX(), position.getY(), position.getZ(), block.getData(), World.BannerColor.valueOf(info.toUpperCase())); - break; - default: - world.setBlock(position.getX(), position.getY(), position.getZ(), block.getId(), block.getData()); + if (position.getY() < 0 || position.getY() >= 255) + return; + + switch (block.getId()) { + + case "minecraft:sign": + world.setSignPost(position.getX(), position.getY(), position.getZ(), block.getProperties(), info); + break; + case "minecraft:wall_sign": + world.setWallSign(position.getX(), position.getY(), position.getZ(), block.getProperties(), info); + break; + case "minecraft:white_banner": + world.setBanner(position.getX(), position.getY(), position.getZ(), block.getProperties(), + World.BannerColor.valueOf(info.toUpperCase())); + break; + default: + world.setBlock(position.getX(), position.getY(), position.getZ(), block.getId(), block.getProperties()); } } - + public String toCSV() { - //if(block == BasicBlock.NonBlock) return null; - if(block.getId() == -1) return null; - return String.format("%d;%d;%d;%d;%d;%s", block.getId(), block.getData(), position.getX(), position.getY(), position.getZ(), (info == null || info.equals("") ? "NULL" : info)); + + if (block.getId().equals("")) { + return null; + } + + String fancyProperties = block.getProperties().entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()) + .collect(Collectors.joining("&")); + + return String.format("%s;%s;%d;%d;%d;%s", block.getId(), fancyProperties, position.getX(), position.getY(), + position.getZ(), (info == null || info.equals("") ? "NULL" : info)); } - + public static Boxel parseCSV(String csv) { String[] parts = csv.split(";"); - return new Boxel( - new BasicBlock( - Short.parseShort(parts[0]), - Integer.parseInt(parts[1])), - new Point( - Integer.parseInt(parts[2]), - Integer.parseInt(parts[3]), - Integer.parseInt(parts[4])), - (parts[5].equals("NULL") ? "" : parts[5]) - ); + Map properties = Collections.emptyMap(); + try { + String[] rawProperties = parts[1].split("&"); + properties = Arrays.stream(rawProperties) + .collect(Collectors.toMap(e -> e.split("=")[0], e -> e.split("=")[1])); + } catch (Exception e2) { + + } + + return new Boxel(new BasicBlock(parts[0], properties), + new Point(Integer.parseInt(parts[2]), Integer.parseInt(parts[3]), Integer.parseInt(parts[4])), + (parts[5].equals("NULL") ? "" : parts[5])); } - + @Override public int toCSVFile(File directory) { int x = position.getX() >> 9; int z = position.getZ() >> 9; - + directory.mkdirs(); String filename = String.format("blocks.%d.%d.csv", x, z); File file = new File(directory, filename); - - try(PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file, true)))) { + + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file, true)))) { String csv = toCSV(); - if(csv != null) writer.println(csv); + if (csv != null) + writer.println(csv); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e1) { @@ -91,4 +109,48 @@ public int getNumberOfBlocks() { return 1; } + @Override + public String toString() { + return "Boxel [block=" + block + ", position=" + position + ", info=" + info + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((block == null) ? 0 : block.hashCode()); + result = prime * result + ((info == null) ? 0 : info.hashCode()); + result = prime * result + ((position == null) ? 0 : position.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Boxel other = (Boxel) obj; + if (block == null) { + if (other.block != null) + return false; + } else if (!block.equals(other.block)) + return false; + if (info == null) { + if (other.info != null) + return false; + } else if (!info.equals(other.info)) + return false; + if (position == null) { + if (other.position != null) + return false; + } else if (!position.equals(other.position)) + return false; + return true; + } + + + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Door.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Door.java index ca210c5f..22da5fd8 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Door.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Door.java @@ -1,29 +1,19 @@ package codemetropolis.toolchain.rendering.model.primitive; import java.io.File; +import java.util.HashMap; +import java.util.Map; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; public class Door implements Primitive { - + public enum Orientation { - NORTH(1), - SOUTH(3), - WEST(0), - EAST(2); - - private final int value; - - Orientation(int v) { - value = v; - } - - public int getValue() { - return value; - } + NORTH, SOUTH, WEST, EAST; + } - + private Point position; private Orientation orientation; @@ -31,17 +21,31 @@ public Door(int x, int y, int z, Orientation orientation) { super(); this.position = new Point(x, y, z); this.orientation = orientation; + } - + @Override public int toCSVFile(File directory) { - new Boxel(new BasicBlock((short) 64, orientation.getValue()), position).toCSVFile(directory); - new Boxel(new BasicBlock((short) 64, 8), new Point(position.getX(), position.getY() + 1, position.getZ())).toCSVFile(directory); + + Map upperDoorProperties = new HashMap<>(); + upperDoorProperties.put("facing", orientation.toString().toLowerCase()); + upperDoorProperties.put("half", "upper"); + + Map lowerDoorProperties = new HashMap<>(); + lowerDoorProperties.put("facing", orientation.toString().toLowerCase()); + lowerDoorProperties.put("half", "lower"); + + BasicBlock upperDoor = new BasicBlock(BasicBlock.DOOR.getId(), upperDoorProperties); + BasicBlock lowerDoor = new BasicBlock(BasicBlock.DOOR.getId(), lowerDoorProperties); + + new Boxel(lowerDoor, position).toCSVFile(directory); + new Boxel(upperDoor, new Point(position.getX(), position.getY() + 1, position.getZ())).toCSVFile(directory); return 2; } + @Override public int getNumberOfBlocks() { return 2; } - + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Row.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Row.java index 2bbc9760..deab4762 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Row.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/Row.java @@ -1,6 +1,8 @@ package codemetropolis.toolchain.rendering.model.primitive; import java.io.File; +import java.util.Arrays; +import java.util.Map; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; @@ -16,23 +18,44 @@ public enum Direction { EAST; } + public enum BlockFacing { + NONE, + NORTH, + SOUTH, + WEST, + EAST; + + } + private Point position; private int length; private Direction orientation; private BasicBlock[] pattern; + private BlockFacing facing; - public Row(Point position, int length, Direction orientation, BasicBlock[] pattern) { + public Row(Point position, int length, Direction orientation, BasicBlock[] pattern, BlockFacing facing) { super(); + this.facing = facing; this.position = position; this.length = length; this.orientation = orientation; this.pattern = pattern; } + public Row(Point position, int length, Direction orientation, BasicBlock[] pattern) { + this(position, length, orientation, pattern, BlockFacing.NONE); + } + @Override public int toCSVFile(File directory) { int c = 0; for(int i = 0; i < length; i++) { + + BasicBlock block = new BasicBlock(pattern[c]); + if(facing != BlockFacing.NONE) { + block.getProperties().put("facing", facing.toString().toLowerCase()); + } + Point blockPos = null; switch(orientation) { case UP: @@ -55,7 +78,7 @@ public int toCSVFile(File directory) { break; } - new Boxel(pattern[c], blockPos).toCSVFile(directory); + new Boxel(block, blockPos).toCSVFile(directory); if(++c > pattern.length - 1) c = 0; } return length; diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/SignPost.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/SignPost.java index ad90f5e1..90d9ad39 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/SignPost.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/SignPost.java @@ -1,33 +1,28 @@ package codemetropolis.toolchain.rendering.model.primitive; import java.io.File; +import java.util.HashMap; +import java.util.Map; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; public class SignPost implements Primitive { - + public enum Orientation { - SOUTH(0), - SOUTHWEST(2), - WEST(4), - NORTHWEST(6), - NORTH(8), - NORTHEAST(10), - EAST(12), - SOUTHEAST(14); - + SOUTH(0), SOUTHWEST(2), WEST(4), NORTHWEST(6), NORTH(8), NORTHEAST(10), EAST(12), SOUTHEAST(14); + private final int value; - + Orientation(int v) { value = v; } - + public int getValue() { return value; } } - + private Point position; private Orientation orientation; private String text; @@ -38,15 +33,22 @@ public SignPost(int x, int y, int z, Orientation orientation, String text) { this.orientation = orientation; this.text = text; } - + @Override public int toCSVFile(File directory) { - new Boxel(new BasicBlock((short) 63, orientation.getValue()), position, text).toCSVFile(directory); + + Map properties = new HashMap<>(); + properties.put("rotation", orientation.getValue() + ""); + + BasicBlock signPost = new BasicBlock(BasicBlock.SIGN.getId(), properties); + + new Boxel(signPost, position, text).toCSVFile(directory); return 1; } + @Override public int getNumberOfBlocks() { return 1; } - + } diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/WallSign.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/WallSign.java index 4c9b8921..ab43ebd7 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/WallSign.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/model/primitive/WallSign.java @@ -1,6 +1,8 @@ package codemetropolis.toolchain.rendering.model.primitive; import java.io.File; +import java.util.HashMap; +import java.util.Map; import codemetropolis.toolchain.commons.cmxml.Point; import codemetropolis.toolchain.rendering.model.BasicBlock; @@ -8,20 +10,10 @@ public class WallSign implements Primitive { public enum Orientation { - NORTH(2), - SOUTH(3), - WEST(4), - EAST(5); - - private final int value; - - Orientation(int v) { - value = v; - } - - public int getValue() { - return value; - } + NORTH, + SOUTH, + WEST, + EAST; } private Point position; @@ -41,7 +33,14 @@ public WallSign(Point position, Orientation orientation, String text) { @Override public int toCSVFile(File directory) { - new Boxel(new BasicBlock((short) 68, orientation.getValue()), position, text).toCSVFile(directory); + + Map properties = new HashMap<>(); + properties.put("facing", orientation.toString().toLowerCase()); + + BasicBlock wallSign = new BasicBlock(BasicBlock.WALL_SIGN.getId(), properties); + + + new Boxel(wallSign, position, text).toCSVFile(directory); return 1; } @Override diff --git a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/util/Character.java b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/util/Character.java index 6dab99fd..41fcf966 100644 --- a/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/util/Character.java +++ b/sources/codemetropolis-toolchain-rendering/src/main/java/codemetropolis/toolchain/rendering/util/Character.java @@ -28,12 +28,15 @@ public enum Character { public static Character parse(String str) { for(Character c : Character.values()) { + System.out.println(c); if(c.toString().equalsIgnoreCase(str)) return c; } return Character.UNDEFINED; } - public BasicBlock getBlock() { + public BasicBlock getBlock() throws Exception { + + switch(this) { case STONE: return new BasicBlock( "minecraft:stone" ); case COBBLESTONE: return new BasicBlock( "minecraft:cobblestone" ); @@ -41,26 +44,26 @@ public BasicBlock getBlock() { case SANDSTONE: return new BasicBlock( "minecraft:sandstone" ); case OBSIDIAN: return new BasicBlock( "minecraft:obsidian" ); case WOOD: return new BasicBlock( "minecraft:log" ); - case DARK_WOOD: return new BasicBlock( "minecraft:log", 1 ); - case BIRCH_WOOD: return new BasicBlock( "minecraft:log", 2 ); + case DARK_WOOD: return new BasicBlock( "minecraft:log"); + case BIRCH_WOOD: return new BasicBlock( "minecraft:log"); case PLANKS: return new BasicBlock( "minecraft:planks" ); - case DARK_PLANKS: return new BasicBlock( "minecraft:planks", 5 ); + case DARK_PLANKS: return new BasicBlock( "minecraft:planks"); case METAL: return new BasicBlock( "minecraft:iron_block" ); case DIRT: return new BasicBlock( "minecraft:dirt" ); - case SAND: return new BasicBlock( "minecraft:sandstone" , 2 ); + case SAND: return new BasicBlock( "minecraft:sandstone"); case RED_SAND: return new BasicBlock( "minecraft:sand" ); - case BRICK: return new BasicBlock( "minecraft:double_stone_slab", 4 ); - case STONE_BRICK: return new BasicBlock( "minecraft:double_stone_slab", 5 ); - case DARK_BRICK: return new BasicBlock( "minecraft:double_stone_slab", 6 ); + case BRICK: return new BasicBlock( "minecraft:double_stone_slab"); + case STONE_BRICK: return new BasicBlock( "minecraft:double_stone_slab" ); + case DARK_BRICK: return new BasicBlock( "minecraft:double_stone_slab"); case GLASS: return new BasicBlock( "minecraft:glass" ); case GOLD: return new BasicBlock( "minecraft:gold_block" ); case DIAMOND: return new BasicBlock( "minecraft:diamond_block" ); - case UNDEFINED: return new BasicBlock( "minecraft:wool", 2 ); - default: return null; + case UNDEFINED: return new BasicBlock( "minecraft:wool" ); + default: throw new Exception("Unsupported Block"); } } - public BasicBlock getTopBlock() { + public BasicBlock getTopBlock() throws Exception { switch(this) { case WOOD: case DARK_WOOD: diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/RenderingExecutorTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/RenderingExecutorTest.java new file mode 100644 index 00000000..1fe0da49 --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/RenderingExecutorTest.java @@ -0,0 +1,74 @@ +package codemetropolis.toolchain.rendering; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; + +import codemetropolis.toolchain.rendering.events.ProgressEvent; +import codemetropolis.toolchain.rendering.events.ProgressEventListener; + +public class RenderingExecutorTest { + + @Test + public void overridePermissionTestWithAccept() { + + RenderingExecutor renderingExecutor = new RenderingExecutor(); + + ByteArrayInputStream in = new ByteArrayInputStream("y".getBytes()); + System.setIn(in); + boolean overridePermission = renderingExecutor.overridePermission(); + assertTrue(overridePermission); + } + + @Test + public void overridePermissionTestWithDenied() { + + RenderingExecutor renderingExecutor = new RenderingExecutor(); + + ByteArrayInputStream in = new ByteArrayInputStream("n".getBytes()); + System.setIn(in); + boolean overridePermission = renderingExecutor.overridePermission(); + assertTrue(!overridePermission); + } + + @Test + public void addEventListenerTest() { + + RenderingExecutor renderingExecutor = new RenderingExecutor(); + int listenerCount = renderingExecutor.getListenerCount(); + ProgressEventListener listener = new ProgressEventListener() { + + @Override + public void onNextState(ProgressEvent event) { + } + }; + + renderingExecutor.addEventListener(listener); + assertTrue(listenerCount + 1 == (renderingExecutor.getListenerCount())); + + } + + @Test + public void removeEventListenerTest() { + + RenderingExecutor renderingExecutor = new RenderingExecutor(); + int listenerCount = renderingExecutor.getListenerCount(); + ProgressEventListener listener = new ProgressEventListener() { + + @Override + public void onNextState(ProgressEvent event) { + } + }; + + renderingExecutor.addEventListener(listener); + assertTrue(listenerCount + 1 == (renderingExecutor.getListenerCount())); + + + renderingExecutor.removeEventListener(listener); + assertTrue(listenerCount == (renderingExecutor.getListenerCount())); + + } + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/BuildingTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/BuildingTest.java new file mode 100644 index 00000000..73679e26 --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/BuildingTest.java @@ -0,0 +1,30 @@ +package codemetropolis.toolchain.rendering.model.building; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class BuildingTest { + + + @Test + public void adjustSizeTestLowerThanMinValue() { + int adjustSize = Building.adjustSize(2); + assertEquals(9, adjustSize); + + } + + @Test + public void adjustSizeTestWithEvenNumber() { + int adjustSize = Building.adjustSize(10); + assertEquals(11, adjustSize); + } + + @Test + public void adjustSizeTestWithOddNumber() { + int adjustSize = Building.adjustSize(11); + assertEquals(11, adjustSize); + + } + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/CellarTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/CellarTest.java new file mode 100644 index 00000000..dd44de71 --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/CellarTest.java @@ -0,0 +1,66 @@ +package codemetropolis.toolchain.rendering.model.building; + +import static org.junit.Assert.*; + +import java.util.LinkedList; + +import org.junit.Test; + +import codemetropolis.toolchain.commons.cmxml.Buildable; +import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; + +public class CellarTest { + + + + @Test + public void constructorTrowExceptionTest() { + try { + new Cellar(new Buildable("test", "testName", Buildable.Type.CONTAINER)); + fail(); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } catch (Exception e) { + fail(); + } + + } + + @Test + public void constructorTest() { + try { + new Cellar(new Buildable("test", "testName", Buildable.Type.CELLAR)); + assertTrue(true); + } catch (BuildingTypeMismatchException e) { + fail(); + } catch (Exception e) { + fail(); + } + + } + + @Test + public void makePrimitivesTest() { + Cellar cellar = null; + + try { + cellar = new Cellar(new Buildable("test", "testName", Buildable.Type.CELLAR)); + + } catch (BuildingTypeMismatchException e) { + fail(); + } catch (Exception e) { + fail(); + } + + LinkedList makePrimitives = cellar.makePrimitives(); + + if(makePrimitives.size() == 2) { + assertTrue(true); + }else { + fail(); + } + + } + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/FloorTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/FloorTest.java new file mode 100644 index 00000000..c0571a5c --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/FloorTest.java @@ -0,0 +1,117 @@ +package codemetropolis.toolchain.rendering.model.building; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.LinkedList; + +import org.junit.Before; +import org.junit.Test; + +import codemetropolis.toolchain.commons.cmxml.Buildable; +import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; +import codemetropolis.toolchain.rendering.model.BasicBlock; +import codemetropolis.toolchain.rendering.model.pattern.Pattern; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; + +public class FloorTest { + + Floor floor; + + + @Before + public void initFloor() { + + try { + floor = new Floor(new Buildable("test", "testName", Buildable.Type.FLOOR)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void constructorTrowExceptionTest() { + try { + new Floor(new Buildable("test", "testName", Buildable.Type.GARDEN)); + fail(); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } catch (Exception e) { + fail(); + } + + } + + @Test + public void prepareSignsTest() { + LinkedList prepareSigns = floor.prepareSigns(); + assertTrue(prepareSigns.size() == 8); + } + + @Test + public void prepareStairTest() { + LinkedList prepareStairs = floor.prepareStairs(); + assertTrue(prepareStairs.size() == 1); + } + + @Test + public void prepareDoorTest() { + LinkedList prepareDoor = floor.prepareDoor(); + assertTrue(prepareDoor.size() == 8); + } + + @Test + public void getStairRepetationPatternTest() { + Pattern stairRepetationPattern = floor.getStairRepetationPattern(); + + if (stairRepetationPattern != null) { + assertTrue(true); + } + + } + + @Test + public void prepareWallsTest() throws Exception { + LinkedList prepareWalls = floor.prepareWalls(); + assertTrue(prepareWalls.size() == 1); + } + + public boolean arrayEqualsTest(BasicBlock[] original, BasicBlock[] expected) { + if (original.length != expected.length) { + return false; + } + + for (int i = 0; i < original.length; i++) { + + if (!(original[i].equals(expected[i]))) { + return false; + } + + } + + return true; + } + + @Test + public void torchPatternTest() { + + BasicBlock torch = BasicBlock.TORCH; + BasicBlock space = BasicBlock.NON_BLOCK; + + BasicBlock[] createTorchPattern0 = floor.createTorchPattern(0, 0); + BasicBlock[] createTorchPattern1 = floor.createTorchPattern(1, 0); + BasicBlock[] createTorchPattern2 = floor.createTorchPattern(2, 0); + BasicBlock[] createTorchPattern3 = floor.createTorchPattern(3, 0); + BasicBlock[] createTorchPattern4 = floor.createTorchPattern(4, 0); + BasicBlock[] createTorchPattern5 = floor.createTorchPattern(5, 0); + + assertTrue("case:0", arrayEqualsTest(createTorchPattern0, new BasicBlock[] { space })); + assertTrue("case:1", + arrayEqualsTest(createTorchPattern1, new BasicBlock[] { torch, space, space, space, space })); + assertTrue("case:2", arrayEqualsTest(createTorchPattern2, new BasicBlock[] { torch, space, space, space })); + assertTrue("case:3", arrayEqualsTest(createTorchPattern3, new BasicBlock[] { torch, space, space })); + assertTrue("case:4", arrayEqualsTest(createTorchPattern4, new BasicBlock[] { torch, space })); + assertTrue("case:5", arrayEqualsTest(createTorchPattern5, new BasicBlock[] { torch })); + } + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GardenTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GardenTest.java new file mode 100644 index 00000000..a56cf46d --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GardenTest.java @@ -0,0 +1,86 @@ +package codemetropolis.toolchain.rendering.model.building; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.LinkedList; + +import org.junit.Test; + +import codemetropolis.toolchain.commons.cmxml.Buildable; +import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; + +public class GardenTest { + + @Test + public void constructorTest() { + Garden garden = null; + try { + garden = new Garden(new Buildable("test", "testName", Buildable.Type.CELLAR)); + fail(); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } + + } + + @Test + public void prepareDoorTest() { + Garden garden = null; + try { + garden = new Garden(new Buildable("test", "testName", Buildable.Type.GARDEN)); + } catch (BuildingTypeMismatchException e) { + fail(); + } + + LinkedList prepareDoor = garden.prepareDoor(); + + if (prepareDoor.size() == 4) { + assertTrue(true); + } else { + fail(); + } + + } + + @Test + public void prepareBaseTest() { + Garden garden = null; + try { + garden = new Garden(new Buildable("test", "testName", Buildable.Type.GARDEN)); + } catch (BuildingTypeMismatchException e) { + fail(); + } + + LinkedList prepareBase = garden.prepareBase(); + + + if (prepareBase.size() == 1) { + assertTrue(true); + } else { + fail(); + } + + } + + @Test + public void prepareSigns() { + Garden garden = null; + try { + garden = new Garden(new Buildable("test", "testName", Buildable.Type.GARDEN)); + } catch (BuildingTypeMismatchException e) { + fail(); + } + + LinkedList prepareSigns = garden.prepareSigns(); + + if (prepareSigns.size() == 4) { + assertTrue(true); + } else { + fail(); + } + + } + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GroundTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GroundTest.java new file mode 100644 index 00000000..ba25bf83 --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/building/GroundTest.java @@ -0,0 +1,67 @@ +package codemetropolis.toolchain.rendering.model.building; + +import static org.junit.Assert.*; + +import java.util.LinkedList; + +import org.junit.Test; + +import codemetropolis.toolchain.commons.cmxml.Buildable; +import codemetropolis.toolchain.rendering.exceptions.BuildingTypeMismatchException; +import codemetropolis.toolchain.rendering.model.primitive.Primitive; + +public class GroundTest { + + @Test + public void constructorTest() { + Ground ground = null; + try { + ground = new Ground(new Buildable("test", "testName", Buildable.Type.CELLAR)); + fail(); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } + + } + + + @Test + public void prepareBaseTest() { + Ground ground = null; + try { + ground = new Ground(new Buildable("test", "testName", Buildable.Type.GROUND)); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } + + LinkedList prepareBase = ground.prepareBase(); + + if (prepareBase.size() == 1) { + assertTrue(true); + } else { + fail(); + } + + } + + @Test + public void prepareSigns() { + Ground ground = null; + try { + ground = new Ground(new Buildable("test", "testName", Buildable.Type.GROUND)); + } catch (BuildingTypeMismatchException e) { + assertTrue(true); + } + + LinkedList prepareSigns = ground.prepareSigns(); + + if (prepareSigns.size() == 4) { + assertTrue(true); + } else { + fail(); + } + + } + + +} diff --git a/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/primitive/BoxelTest.java b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/primitive/BoxelTest.java new file mode 100644 index 00000000..54d3c7a7 --- /dev/null +++ b/sources/codemetropolis-toolchain-rendering/src/test/java/codemetropolis/toolchain/rendering/model/primitive/BoxelTest.java @@ -0,0 +1,52 @@ +package codemetropolis.toolchain.rendering.model.primitive; + +import static org.junit.Assert.*; + +import javax.swing.Box; + +import org.junit.Test; + +import codemetropolis.toolchain.commons.cmxml.Point; +import codemetropolis.toolchain.rendering.model.BasicBlock; + +public class BoxelTest { + + @Test + public void toCSVTestWithoutProperties() { + Boxel boxel = new Boxel(BasicBlock.AIR, new Point(0, 0, 0), "testInfo"); + + String csv = boxel.toCSV(); + String expected = "minecraft:air;;0;0;0;testInfo"; + + assertTrue(expected.equals(csv)); + } + + @Test + public void toCSVTestWithProperties() { + Boxel boxel = new Boxel(BasicBlock.REDSTONE_LAMP, new Point(0, 0, 0), "testInfo"); + + String csv = boxel.toCSV(); + String expected = "minecraft:redstone_lamp;lit=true;0;0;0;testInfo"; + + assertTrue(expected.equals(csv)); + } + + @Test + public void parseCSVWithoutProperties() { + + Boxel parsed = Boxel.parseCSV("minecraft:air;;0;0;0;testInfo"); + Boxel expected = new Boxel(BasicBlock.AIR, new Point(0, 0, 0), "testInfo"); + + assertTrue(expected.equals(parsed)); + } + + @Test + public void parseCSVWithProperties() { + + Boxel parsed = Boxel.parseCSV("minecraft:redstone_lamp;lit=true;0;0;0;testInfo"); + Boxel expected = new Boxel(BasicBlock.REDSTONE_LAMP, new Point(0, 0, 0), "testInfo"); + + assertTrue(expected.equals(parsed)); + } + +}