package net.knarcraft.stargate.portal; import net.knarcraft.stargate.container.RelativeBlockVector; import java.io.BufferedWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * The gate layout describes where every part of the gate should be * *
The gate layout parses a layout described by a Character matrix and stores the different parts of the gate as * relative block vectors. All relative vectors has an origin in the top-left block when looking at the gate's front * (the side with the sign)
*/ public class GateLayout { private final Character[][] layout; private final ListA character array describing the layout
*/ public GateLayout(Character[][] layout) { this.layout = layout; readLayout(); } /** * Gets two of the corners of the gate layout creating the smallest box the gate can be contained within * * @returnTwo of the gate's corners
*/ public RelativeBlockVector[] getCorners() { return new RelativeBlockVector[]{ new RelativeBlockVector(0, 0, 0), new RelativeBlockVector(layout[0].length - 1, layout.length - 1, 1) }; } /** * Gets the character array describing this layout * * @returnThe character array describing this layout
*/ public Character[][] getLayout() { return this.layout; } /** * Gets the locations of entrances for this gate * * @returnThe locations of entrances for this gate
*/ public RelativeBlockVector[] getEntrances() { return entrances; } /** * Gets the locations of border blocks for the gate described by this layout * *A border block is basically any block of the frame. In terms of the nether gate, the border blocks are every * block of the gate that's not air when the gate is closed. The sign and button are not border blocks.
* * @returnThe locations of border blocks for this gate
*/ public RelativeBlockVector[] getBorder() { return border; } /** * Gets the exit block defined in the layout * * @returnThe exit block defined in the layout
*/ public RelativeBlockVector getExit() { return exitBlock; } /** * Gets other possible exits of the gate * * @returnOther possible gate exits
*/ public ListThe control blocks are the blocks where a sign can be placed to create a portal.
* * @returnThe locations of the control blocks for this gate
*/ public RelativeBlockVector[] getControls() { return controls; } /** * Saves the gate layout using a buffered writer * * @param bufferedWriterThe buffered writer to write to
* @throws IOExceptionIf unable to write to the buffered writer
*/ public void save(BufferedWriter bufferedWriter) throws IOException { for (Character[] line : this.layout) { for (Character symbol : line) { bufferedWriter.append(symbol); } bufferedWriter.newLine(); } } /** * Reads the gate layout to relative block vectors */ private void readLayout() { ListThe list of control blocks to save to
* @param entranceListThe list of entrances to save to
* @param borderListThe list of border blocks to save to
* @returnA list of depths of possible extra exits
*/ private int[] readLayout(ListThe character read
* @param rowIndexThe row of the read character
* @param lineIndexThe line of the read character
* @param exitDepthsThe list of exit depths to save to
* @param controlListThe list of control blocks to save to
* @param entranceListThe list of entrances to save to
* @param borderListThe list of border blocks to save to
*/ private void parseLayoutCharacter(Character key, int rowIndex, int lineIndex, int[] exitDepths, List