/** * @param sign treated as sign post if it is such, or else assumed to be a wall sign (i.e., * if you ask about a stone block, it's considered a wall * sign). * @return the direction a player would be facing when reading the sign; i.e. the face that is actually the back * side of the sign. */ public static Direction getFacing(Location<World> sign) { return getBack(sign); }
public static Location<World> getBackBlock(Location<World> sign) { return sign.getRelative(getBack(sign)); }
@Override public BlockBag getBlockBag(Location<World> location) { BlockBag mainBlockBag = super.getBlockBag(location); Location<World> next = BlockUtil.getNextMatchingSign(location, SignUtil.getBack(location), 2, this::isMechanicSign); if (next != null) { BlockBag nextBlockBag = super.getBlockBag(next); if (nextBlockBag != null) { return new MultiBlockBag(mainBlockBag, nextBlockBag); } } return mainBlockBag; }
public static Location<World> getNextSign(Location<World> sign, String criterea, int searchRadius) { Location<World> otherBlock = sign; Direction way = getBack(sign); boolean found = false; for (int i = 0; i < searchRadius; i++) { if (isSign(otherBlock.getRelative(way))) { otherBlock = otherBlock.getRelative(way); if(getTextRaw((Sign) otherBlock.getTileEntity().get(), 1).equalsIgnoreCase(criterea)) { found = true; break; } } else otherBlock = otherBlock.getRelative(way); } if (!found) return null; return otherBlock; }
@Override public Location<World> getPinLocation(int id, IC ic) { switch(id) { case 0: return ic.getBlock().getRelative(SignUtil.getFront(ic.getBlock())); case 1: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())); case 2: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getLeft(ic.getBlock())); case 3: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getRight(ic.getBlock())); default: return null; } } }
@Override public Location<World> getPinLocation(int id, IC ic) { switch(id) { case 0: return ic.getBlock().getRelative(SignUtil.getFront(ic.getBlock())); case 1: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())); case 2: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getLeft(ic.getBlock())); case 3: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getRight(ic.getBlock())); case 4: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getLeft(ic.getBlock())); case 5: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getRight(ic.getBlock())); default: return null; } } }
@Override public BlockBag getBlockBag(Location<World> location) { BlockBag mainBlockBag = super.getBlockBag(location); Location<World> next = BlockUtil.getNextMatchingSign(location, SignUtil.getBack(location), maximumLength.getValue() + 2, this::isMechanicSign); if (next != null) { BlockBag nextBlockBag = super.getBlockBag(next); if (nextBlockBag != null) { return new MultiBlockBag(mainBlockBag, nextBlockBag); } } return mainBlockBag; }
@Listener public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) { event.getTargetBlock().getLocation().ifPresent((location) -> { Location<World> signLocation = location; if (allowButtonLifts.getValue() && signLocation.getBlockType() == BlockTypes.STONE_BUTTON || signLocation.getBlockType() == BlockTypes.WOODEN_BUTTON) { Direction backDir = SignUtil.getBack(signLocation); signLocation = signLocation.getRelative(backDir).getRelative(backDir); } if (SignUtil.isSign(signLocation)) { Sign sign = (Sign) signLocation.getTileEntity().get(); Optional<Vector3d> interactionPoint = event.getInteractionPoint(); boolean down = "[Lift Down]".equals(SignUtil.getTextRaw(sign, 1)) || ("[Lift UpDown]".equals(SignUtil.getTextRaw(sign, 1)) && interactionPoint.isPresent() && interactionPoint.get().getY() < 0.5); if (down || "[Lift Up]".equals(SignUtil.getTextRaw(sign, 1)) || ("[Lift UpDown]".equals(SignUtil.getTextRaw(sign, 1)) && interactionPoint.isPresent() && interactionPoint.get().getY() > 0.5)) { if (!usePermissions.hasPermission(player)) { player.sendMessage(Text.of(TextColors.RED, "You don't have permission to use this mechanic!")); return; } transportEntity(player, location, down ? Direction.DOWN : Direction.UP); } } }); }
@Override public Location<World> getPinLocation(int id, IC ic) { switch(id) { case 0: return ic.getBlock().getRelative(SignUtil.getFront(ic.getBlock())); case 1: return ic.getBlock().getRelative(SignUtil.getLeft(ic.getBlock())); case 2: return ic.getBlock().getRelative(SignUtil.getRight(ic.getBlock())); case 3: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())); case 4: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getLeft(ic.getBlock())); case 5: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getRight(ic.getBlock())); default: return null; } }
/** * Find a {@link CartMechanismBlocks} from a sign. * * @param block The sign to search from. * @return The CartMechanismBlocks, if found */ public static Optional<CartMechanismBlocks> findBySign(Location<World> block) { if (!SignUtil.isSign(block)) { return Optional.empty(); } if (BlockUtil.isTrack(block.getRelative(Direction.UP).getRelative(Direction.UP).getBlockType())) { return Optional.of(new CartMechanismBlocks( block.getRelative(Direction.UP).getRelative(Direction.UP), block.getRelative(Direction.UP), block)); } else if (BlockUtil.isTrack(block.getRelative(Direction.UP).getRelative(Direction.UP).getRelative(Direction.UP).getBlockType())) { return Optional.of(new CartMechanismBlocks( block.getRelative(Direction.UP).getRelative(Direction.UP).getRelative(Direction.UP), block.getRelative(Direction.UP).getRelative(Direction.UP), block)); } else if (BlockUtil.isTrack(block.getRelative(SignUtil.getBack(block)).getRelative(Direction.UP).getBlockType())) { return Optional.of(new CartMechanismBlocks( block.getRelative(SignUtil.getBack(block)).getRelative(Direction.UP), block.getRelative(SignUtil.getBack(block)), block)); } else { return Optional.empty(); } }
@Override public Location<World> getPinLocation(int id, IC ic) { switch(id) { case 0: return ic.getBlock().getRelative(SignUtil.getFront(ic.getBlock())); case 1: return ic.getBlock().getRelative(SignUtil.getLeft(ic.getBlock())); case 2: return ic.getBlock().getRelative(SignUtil.getRight(ic.getBlock())); case 3: return ic.getBlock().getRelative(SignUtil.getBack(ic.getBlock())).getRelative(SignUtil.getBack(ic.getBlock())); default: return null; } }
/** * Gets the destination of an Elevator. If there is none, it returns the start. * * @param block The starting block. * @param direction The direction to move in. * @return The elevator destination. */ private Location<World> findDestination(Location<World> block, Direction direction) { int y = block.getBlockY(); if (direction == Direction.UP || direction == Direction.DOWN) { while (direction == Direction.UP ? y < 255 : y > 0) { y += direction == Direction.UP ? 1 : -1; Location<World> test = block.getExtent().getLocation(block.getBlockX(), y, block.getBlockZ()); if (allowButtonLifts.getValue() && test.getBlockType() == BlockTypes.STONE_BUTTON || test.getBlockType() == BlockTypes.WOODEN_BUTTON) { Direction backDir = SignUtil.getBack(test); test = test.getRelative(backDir).getRelative(backDir); } if (SignUtil.isSign(test)) { // It's a sign. if(isValid(test)) return test; } } } // We don't currently support non-up/down elevators, this isn't a Roald Dahl novel. return block; }
Direction backDir = SignUtil.getBack(signLocation); signLocation = signLocation.getRelative(backDir).getRelative(backDir);
@Override public boolean triggerMechanic(Location<World> block, Sign sign, Humanoid human, Boolean forceState) { if (!"[Bridge End]".equals(SignUtil.getTextRaw(sign, 1))) { Direction back = SignUtil.getBack(block); baseBlock = block.getRelative(SignUtil.getBack(block)); Location<World> otherSide = BlockUtil.getNextMatchingSign(block, SignUtil.getBack(block), maximumLength.getValue(), this::isMechanicSign); if (otherSide == null) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(missingOtherEnd); otherBase = otherSide.getRelative(SignUtil.getBack(otherSide)); type = block.getRelative(SignUtil.getBack(block)).getBlock();