示例#1
0
 /**
  * Detecting factory, based on the position of the sign. The base must be one or two blocks above
  * and the rails an additional block above the base. Signs are guaranteed to be signs and rails
  * are guaranteed to be rails.
  *
  * @param sign the block containing the sign that gives additional configuration to the mechanism.
  */
 public static CartMechanismBlocks findBySign(Block sign) throws InvalidMechanismException {
   if (!SignUtil.isSign(sign))
     throw new InvalidMechanismException("sign argument must be a sign!");
   if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 2).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 2), sign.getFace(BlockFace.UP, 1), sign);
   } else if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 3).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 3), sign.getFace(BlockFace.UP, 2), sign);
   }
   throw new InvalidMechanismException("could not find rails.");
 }
示例#2
0
 /**
  * Detecting factory, based on the position of the base. The rails must be one block above and the
  * sign if it exists must be one or two blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * @param base the block on which the rails sit; the type of this block is what determines the
  *     mechanism type.
  */
 public static CartMechanismBlocks findByBase(Block base) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(base.getFace(BlockFace.UP, 1).getTypeId()))
     throw new InvalidMechanismException("could not find rails.");
   if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 1).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 1));
   } else if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 2));
   }
   return new CartMechanismBlocks(base.getFace(BlockFace.UP, 1), base, null);
 }
示例#3
0
 /**
  * Detecting factory, based on the position of the rails. The base must be one block below and the
  * sign if it exists must be two or three blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * <p>This is the most important constructor, since it is the one invoked when processing cart
  * move events.
  *
  * @param rail the block containing the rails.
  */
 public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(rail.getTypeId()))
     throw new InvalidMechanismException("rail argument must be a rail!");
   if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 2));
   } else if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 3).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 3));
   }
   return new CartMechanismBlocks(rail, rail.getFace(BlockFace.DOWN, 1), null);
 }
示例#4
0
 /**
  * Detecting factory; defers to one of the other three specific detecting factories based on
  * whether the given unknown block appears to be a sign, rail, or base.
  *
  * @param unknown the block to examine.
  */
 public static CartMechanismBlocks find(Block unknown) throws InvalidMechanismException {
   final int ti = unknown.getTypeId();
   if (SignUtil.isSign(ti)) return findBySign(unknown);
   else if (BlockType.isRailBlock(ti)) return findByRail(unknown);
   else return findByBase(unknown);
 }