}
@Override
public CuboidRegion getCuboidArea(Block trigger, Block proximalBaseCenter, Block distalBaseCenter) throws InvalidMechanismException {
// Select the togglable region
CuboidRegion toggle = new CuboidRegion(BukkitUtil.toVector(proximalBaseCenter), BukkitUtil.toVector(distalBaseCenter));
ChangedSign sign = BukkitUtil.toChangedSign(trigger);
int left, right;
try {
left = Math.max(0, Math.min(maxWidth, Integer.parseInt(sign.getLine(2))));
} catch (Exception e) {
left = 1;
}
try {
right = Math.max(0, Math.min(maxWidth, Integer.parseInt(sign.getLine(3))));
} catch (Exception e) {
right = 1;
}
// Expand Left
for (int i = 0; i < left; i++) {
if(distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getType() && distalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getData() != proximalBaseCenter.getRelative(SignUtil.getLeft(trigger), i).getData())
throw new InvalidMechanismException("mech.door.material");
toggle.expand(BukkitUtil.toVector(SignUtil.getLeft(trigger)), new Vector(0, 0, 0));
}
// Expand Right
for (int i = 0; i < right; i++) {
if(distalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType() != proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getType() && distalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getData() != proximalBaseCenter.getRelative(SignUtil.getRight(trigger), i).getData())
throw new InvalidMechanismException("mech.door.material");
toggle.expand(BukkitUtil.toVector(SignUtil.getRight(trigger)), new Vector(0, 0, 0));
}
// Don't toggle the end points
toggle.contract(BukkitUtil.toVector(BlockFace.UP), BukkitUtil.toVector(BlockFace.DOWN));
return toggle;
}