return getBlockStates(info, radius.x, radius.z);
}
public static Collection<BlockState> getBlockStates(SignActionEvent info, int radWidth, int radHeight) {
// Obtain the BlockFaces using absolute width and height
final Block centerBlock = info.getRails();
int radX = Math.abs(radWidth);
int radY = Math.abs(radHeight);
int radZ = Math.abs(radWidth);
BlockFace dir = info.getRailDirection();
if (FaceUtil.isVertical(dir)) {
radY = 0;
} else if (FaceUtil.isAlongX(dir)) {
radX = 0;
} else if (FaceUtil.isAlongZ(dir)) {
radZ = 0;
}
List<BlockState> states = new ArrayList<BlockState>(BlockUtil.getBlockStates(centerBlock, radX, radY, radZ));
// Get rid of twice-stored double chests
try {
Iterator<BlockState> iter = states.iterator();
while (iter.hasNext()) {
BlockState next = iter.next();
if (!(next instanceof Chest)) {
continue;
}
DoubleChestInventory inventory = CommonUtil.tryCast(((Chest) next).getInventory(), DoubleChestInventory.class);
if (inventory == null) {
continue;
}
if (chestsBuffer.add(inventory.getLeftSide().getHolder()) &&
chestsBuffer.add(inventory.getRightSide().getHolder())) {
continue;
}
// Already added chest(s), disregard
iter.remove();
}
} finally {
chestsBuffer.clear();
}
// Sort the resulting states based on distance from the center
final boolean widthInv = radWidth < 0;
final boolean heightInv = radHeight < 0;
Collections.sort(states, new Comparator<BlockState>() {
public int getIndex(BlockState state) {
int dx = MathUtil.invert(Math.abs(centerBlock.getX() - state.getX()), widthInv);
int dy = MathUtil.invert(Math.abs(centerBlock.getY() - state.getY()), heightInv);
int dz = MathUtil.invert(Math.abs(centerBlock.getZ() - state.getZ()), widthInv);
// Magical formula timez!
return dx + 16 * dz + 256 * dy;
}
@Override