Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BlockFace.java
1 package org.bukkit.block;
2 
3 /**
4  * Represents the face of a block
5  */
6 public enum BlockFace {
7  NORTH(0, 0, -1),
8  EAST(1, 0, 0),
9  SOUTH(0, 0, 1),
10  WEST(-1, 0, 0),
11  UP(0, 1, 0),
12  DOWN(0, -1, 0),
13  NORTH_EAST(NORTH, EAST),
14  NORTH_WEST(NORTH, WEST),
15  SOUTH_EAST(SOUTH, EAST),
16  SOUTH_WEST(SOUTH, WEST),
17  WEST_NORTH_WEST(WEST, NORTH_WEST),
18  NORTH_NORTH_WEST(NORTH, NORTH_WEST),
19  NORTH_NORTH_EAST(NORTH, NORTH_EAST),
20  EAST_NORTH_EAST(EAST, NORTH_EAST),
21  EAST_SOUTH_EAST(EAST, SOUTH_EAST),
22  SOUTH_SOUTH_EAST(SOUTH, SOUTH_EAST),
23  SOUTH_SOUTH_WEST(SOUTH, SOUTH_WEST),
24  WEST_SOUTH_WEST(WEST, SOUTH_WEST),
25  SELF(0, 0, 0);
26 
27  private final int modX;
28  private final int modY;
29  private final int modZ;
30 
31  private BlockFace(final int modX, final int modY, final int modZ) {
32  this.modX = modX;
33  this.modY = modY;
34  this.modZ = modZ;
35  }
36 
37  private BlockFace(final BlockFace face1, final BlockFace face2) {
38  this.modX = face1.getModX() + face2.getModX();
39  this.modY = face1.getModY() + face2.getModY();
40  this.modZ = face1.getModZ() + face2.getModZ();
41  }
42 
43  /**
44  * Get the amount of X-coordinates to modify to get the represented block
45  *
46  * @return Amount of X-coordinates to modify
47  */
48  public int getModX() {
49  return modX;
50  }
51 
52  /**
53  * Get the amount of Y-coordinates to modify to get the represented block
54  *
55  * @return Amount of Y-coordinates to modify
56  */
57  public int getModY() {
58  return modY;
59  }
60 
61  /**
62  * Get the amount of Z-coordinates to modify to get the represented block
63  *
64  * @return Amount of Z-coordinates to modify
65  */
66  public int getModZ() {
67  return modZ;
68  }
69 
70  public BlockFace getOppositeFace() {
71  switch (this) {
72  case NORTH:
73  return BlockFace.SOUTH;
74 
75  case SOUTH:
76  return BlockFace.NORTH;
77 
78  case EAST:
79  return BlockFace.WEST;
80 
81  case WEST:
82  return BlockFace.EAST;
83 
84  case UP:
85  return BlockFace.DOWN;
86 
87  case DOWN:
88  return BlockFace.UP;
89 
90  case NORTH_EAST:
91  return BlockFace.SOUTH_WEST;
92 
93  case NORTH_WEST:
94  return BlockFace.SOUTH_EAST;
95 
96  case SOUTH_EAST:
97  return BlockFace.NORTH_WEST;
98 
99  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 }