package us.illyohs.azathoth.pattern;

import java.util.HashMap;

import net.minecraft.block.Block;

import us.illyohs.azathoth.world.SigBlock;
import us.illyohs.azathoth.world.WorldXYZ;

public abstract class Pattern {
    
    public Pattern() {}
    
    /**
     * The pattern 
     */
    protected abstract Block[][][] patternTemplate();
    
    public abstract boolean isFlatPatternOnly();
    
    protected HashMap<WorldXYZ, SigBlock> patternFormulae(WorldXYZ coords) {
        if (isFlatPatternOnly())
            coords = coords.copyWithNewFacing(1);
            return patternToShape(patternTemplate(), coords);

    }

    private HashMap<WorldXYZ, SigBlock> patternToShape(Block[][][] pattern, WorldXYZ centerPoint) {
        HashMap<WorldXYZ, SigBlock> shape = new HashMap<WorldXYZ, SigBlock>();
        for (int y = 0; y < pattern.length; y++) {
            for (int z = 0; z < pattern[y].length; z++) {
                for (int x = 0; x < pattern[y][z].length; x++) {
                    WorldXYZ target;
                    
                    switch(centerPoint.face) {
                    case 1: //laying flat activated from top or bottom
                    case 0:
                        target = centerPoint.offset(-pattern[y][z].length / 2 + x,  -y,  -pattern[y].length / 2 + z);//TODO: clockwise vs CCW?
                        break;
                    case 2://NORTH or SOUTH which points along the z axis
                    case 3://this means that flat patterns (XZ pattern) will extend along XY
                        target = centerPoint.offset(-pattern[y][z].length / 2 + x,  pattern[y].length / 2 - z,  -y );//TODO: +y for SOUTH
                        break;
                    case 4://WEST or EAST facing
                    case 5://flat patterns extend along the ZY plane
                        target = centerPoint.offset(-y,  pattern[y][z].length / 2 - x,  -pattern[y].length / 2 + z);
                        break;
                    default:
                        System.err.println("Block facing not recognized: " + centerPoint.face + " should be 0-5.");
                        target = centerPoint;
                    }
                }
            }
        }
        return shape;
    }
    
}

@@ -1,8 +1,1408 @@
+/**%0A *  Copyright (c) 2014, Runix-Minecraft%0A *  All rights reserved.%0A *  %0A *  Redistribution and use in source and binary forms, with or without%0A *  modification, are permitted provided that the following conditions are met:%0A *  %0A *  * Redistributions of source code must retain the above copyright notice, this%0A *    list of conditions and the following disclaimer.%0A *    %0A *  * Redistributions in binary form must reproduce the above copyright notice,%0A *    this list of conditions and the following disclaimer in the documentation%0A *    and/or other materials provided with the distribution.%0A *  %0A *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22%0A *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE%0A *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE%0A *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL%0A *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR%0A *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER%0A *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,%0A *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0A *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A
 package 

Add license header