001 package org.bukkit.block; 002 003 /** 004 * Represents the face of a block 005 */ 006 public enum BlockFace { 007 NORTH(0, 0, -1), 008 EAST(1, 0, 0), 009 SOUTH(0, 0, 1), 010 WEST(-1, 0, 0), 011 UP(0, 1, 0), 012 DOWN(0, -1, 0), 013 NORTH_EAST(NORTH, EAST), 014 NORTH_WEST(NORTH, WEST), 015 SOUTH_EAST(SOUTH, EAST), 016 SOUTH_WEST(SOUTH, WEST), 017 WEST_NORTH_WEST(WEST, NORTH_WEST), 018 NORTH_NORTH_WEST(NORTH, NORTH_WEST), 019 NORTH_NORTH_EAST(NORTH, NORTH_EAST), 020 EAST_NORTH_EAST(EAST, NORTH_EAST), 021 EAST_SOUTH_EAST(EAST, SOUTH_EAST), 022 SOUTH_SOUTH_EAST(SOUTH, SOUTH_EAST), 023 SOUTH_SOUTH_WEST(SOUTH, SOUTH_WEST), 024 WEST_SOUTH_WEST(WEST, SOUTH_WEST), 025 SELF(0, 0, 0); 026 027 private final int modX; 028 private final int modY; 029 private final int modZ; 030 031 private BlockFace(final int modX, final int modY, final int modZ) { 032 this.modX = modX; 033 this.modY = modY; 034 this.modZ = modZ; 035 } 036 037 private BlockFace(final BlockFace face1, final BlockFace face2) { 038 this.modX = face1.getModX() + face2.getModX(); 039 this.modY = face1.getModY() + face2.getModY(); 040 this.modZ = face1.getModZ() + face2.getModZ(); 041 } 042 043 /** 044 * Get the amount of X-coordinates to modify to get the represented block 045 * 046 * @return Amount of X-coordinates to modify 047 */ 048 public int getModX() { 049 return modX; 050 } 051 052 /** 053 * Get the amount of Y-coordinates to modify to get the represented block 054 * 055 * @return Amount of Y-coordinates to modify 056 */ 057 public int getModY() { 058 return modY; 059 } 060 061 /** 062 * Get the amount of Z-coordinates to modify to get the represented block 063 * 064 * @return Amount of Z-coordinates to modify 065 */ 066 public int getModZ() { 067 return modZ; 068 } 069 070 public BlockFace getOppositeFace() { 071 switch (this) { 072 case NORTH: 073 return BlockFace.SOUTH; 074 075 case SOUTH: 076 return BlockFace.NORTH; 077 078 case EAST: 079 return BlockFace.WEST; 080 081 case WEST: 082 return BlockFace.EAST; 083 084 case UP: 085 return BlockFace.DOWN; 086 087 case DOWN: 088 return BlockFace.UP; 089 090 case NORTH_EAST: 091 return BlockFace.SOUTH_WEST; 092 093 case NORTH_WEST: 094 return BlockFace.SOUTH_EAST; 095 096 case SOUTH_EAST: 097 return BlockFace.NORTH_WEST; 098 099 case SOUTH_WEST: 100 return BlockFace.NORTH_EAST; 101 102 case WEST_NORTH_WEST: 103 return BlockFace.EAST_SOUTH_EAST; 104 105 case NORTH_NORTH_WEST: 106 return BlockFace.SOUTH_SOUTH_EAST; 107 108 case NORTH_NORTH_EAST: 109 return BlockFace.SOUTH_SOUTH_WEST; 110 111 case EAST_NORTH_EAST: 112 return BlockFace.WEST_SOUTH_WEST; 113 114 case EAST_SOUTH_EAST: 115 return BlockFace.WEST_NORTH_WEST; 116 117 case SOUTH_SOUTH_EAST: 118 return BlockFace.NORTH_NORTH_WEST; 119 120 case SOUTH_SOUTH_WEST: 121 return BlockFace.NORTH_NORTH_EAST; 122 123 case WEST_SOUTH_WEST: 124 return BlockFace.EAST_NORTH_EAST; 125 126 case SELF: 127 return BlockFace.SELF; 128 } 129 130 return BlockFace.SELF; 131 } 132 }