001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.base;
019
020import net.tridentsdk.util.Vector;
021
022/**
023 * Represents an orientation towards a given direction set from a {@link net.tridentsdk.util.Vector}
024 *
025 * @author The TridentSDK Team
026 * @since 0.3-alpha-DP
027 */
028public enum BlockDirection {
029    /**
030     * Facing north
031     */
032    NORTH(new Vector(0, 0, -1)),
033    /**
034     * Facing south
035     */
036    SOUTH(new Vector(0, 0, 1)),
037    /**
038     * Facing east
039     */
040    EAST(new Vector(1, 0, 0)),
041    /**
042     * Facing west
043     */
044    WEST(new Vector(-1, 0, 0)),
045
046    /**
047     * Facing north east
048     */
049    NORTH_EAST(NORTH, EAST),
050    /**
051     * Facing north west
052     */
053    NORTH_WEST(NORTH, WEST),
054    /**
055     * Facing south east
056     */
057    SOUTH_EAST(SOUTH, EAST),
058    /**
059     * Facing south west
060     */
061    SOUTH_WEST(SOUTH, WEST),
062
063    /**
064     * Facing up
065     */
066    TOP(new Vector(0.0D, 1.0D, 0.0D)),
067    /**
068     * Facing down
069     */
070    BOTTOM(new Vector(0.0D, -1.0D, 0.0D)),
071
072    /**
073     * The given component direction not leading anywhere
074     */
075    SELF(new Vector(0, 0, 0));
076
077    private final Vector difference;
078
079    BlockDirection(Vector difference) {
080        this.difference = difference;
081    }
082
083    BlockDirection(BlockDirection face1, BlockDirection face2) {
084        this.difference = face1.difference().add(face2.difference());
085    }
086
087    /**
088     * The copy of the directional vector
089     *
090     * @return the cloned vector pointing to the specified face
091     */
092    public Vector difference() {
093        return this.difference.clone();
094    }
095
096    /**
097     * Gets the position relative to the given direction
098     *
099     * @param loc the position to get relative to
100     * @return the relative position
101     */
102    public Position apply(Position loc) {
103        return loc.relative(this.difference);
104    }
105}