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; }
public static Location<World> getRelativeOffset(Location<World> block, int offsetX, int offsetY, int offsetZ) { return getRelativeOffset(SignUtil.getBackBlock(block), SignUtil.getFacing(block), offsetX, offsetY, offsetZ); }
/** * @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 cardinal or ordinal direction to a player's left as they face the sign to read it; if the sign is * oriented in a further direction, * the result is rounded to the nearest ordinal direction. */ public static Direction getRight(Location<World> sign) { Direction front = getFront(sign); if (front == null) return Direction.NONE; return getClockWise(front); }
/** * @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 cardinal or ordinal direction to a player's right they face the sign to read it; if the sign is * oriented in a further direction, the * result is rounded to the nearest ordinal direction. */ public static Direction getLeft(Location<World> sign) { Direction front = getFront(sign); if (front == null) return Direction.NONE; return getCounterClockWise(front); }
public static String getTextRaw(SignData sign, int line) { return getTextRaw(getText(sign, line)); }
@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 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)); Location<World> left = baseBlock.getRelative(SignUtil.getLeft(block)); Location<World> right = baseBlock.getRelative(SignUtil.getRight(block)); Location<World> otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); leftBlocks = BlockUtil.getMinimumLength(left, otherLeft, baseBlock.getBlock(), SignUtil.getLeft(block), maximumWidth.getValue()); Location<World> otherRight = otherBase.getRelative(SignUtil.getRight(block)); rightBlocks = BlockUtil.getMinimumLength(right, otherRight, baseBlock.getBlock(), SignUtil.getRight(block), maximumWidth.getValue()); type = block.getRelative(SignUtil.getBack(block)).getBlock(); left = baseBlock.getRelative(SignUtil.getLeft(block)); left = left.getRelative(SignUtil.getLeft(block));
@Override public boolean triggerMechanic(Location<World> block, Sign sign, Humanoid human, Boolean forceState) { if (!"[Door]".equals(SignUtil.getTextRaw(sign, 1))) { Direction back = "[Door Up]".equals(SignUtil.getTextRaw(sign, 1)) ? Direction.UP : Direction.DOWN; Location<World> left = baseBlock.getRelative(SignUtil.getLeft(block)); Location<World> right = baseBlock.getRelative(SignUtil.getRight(block)); Location<World> otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); if(left.getBlock().equals(baseBlock.getBlock()) && otherLeft.getBlock().equals(baseBlock.getBlock())) { leftBlocks ++; left = left.getRelative(SignUtil.getLeft(block)); otherLeft = otherLeft.getRelative(SignUtil.getLeft(block)); } else { break; Location<World> otherRight = otherBase.getRelative(SignUtil.getRight(block)); if(right.getBlock().equals(baseBlock.getBlock()) && otherRight.getBlock().equals(baseBlock.getBlock())) { rightBlocks ++; right = right.getRelative(SignUtil.getRight(block)); otherRight = otherRight.getRelative(SignUtil.getRight(block)); } else { break; left = baseBlock.getRelative(SignUtil.getLeft(block)); left = left.getRelative(SignUtil.getLeft(block));
/** * 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 boolean isValid(Location<World> location) { if (location.getBlock().equals(block.getValue())) { if (requireSign.getValue()) { for (Location<World> attachedSign : SignUtil.getAttachedSigns(location)) { if (isMechanicSign(attachedSign.getTileEntity().map(tile -> (Sign) tile).get())) { return true; } } } else { return true; } } else { return SignUtil.isSign(location) && isMechanicSign(location.getTileEntity().map(tile -> (Sign) tile).get()); } return false; }
private boolean hasSign(Location<World> location, List<Location<World>> searched, Location<World> original) { boolean found = false; for (Direction face : BlockUtil.getDirectFaces()) { Location<World> otherBlock = location.getRelative(face); if (searched.contains(otherBlock)) continue; searched.add(otherBlock); if (found) break; if (location.getPosition().distanceSquared(original.getPosition()) > Math.pow(maxSignDistance.getValue(), 2)) continue; if (SignUtil.isSign(otherBlock) && SignUtil.getFront(otherBlock) == face) { found = true; break; } if (Objects.equals(location.getBlockType(), otherBlock.getBlockType())) { found = hasSign(otherBlock, searched, original); } } return found; }
lastTick = Math.max(0, Integer.parseInt(SignUtil.getTextRaw(sign, 2))); } catch (Exception e) { List<Text> lines = sign.lines().get(); Location<?> baseBlock = SignUtil.getBackBlock(location); Location<?> chestBlock = baseBlock.add(0, 2, 0);
@Listener public void onEntityMove(MoveEntityEvent event) { if(!allowJumpLifts.getValue()) return; if(!LocationUtil.isLocationWithinWorld(event.getToTransform().getLocation())) return; Location<World> groundLocation = event.getToTransform().getLocation().getRelative(Direction.DOWN); //Look for dat sign for (Location<World> location : SignUtil.getAttachedSigns(groundLocation)) { Sign sign = (Sign) location.getTileEntity().orElse(null); if (sign != null && "[Lift UpDown]".equals(SignUtil.getTextRaw(sign, 1))) { if (event.getTargetEntity() instanceof Subject) { if (!usePermissions.hasPermission((Subject) event.getTargetEntity())) { return; } } if (event.getToTransform().getPosition().getY() > event.getFromTransform().getPosition().getY()) { transportEntity(event.getTargetEntity(), location, Direction.UP); //Jump is up } else if (event.getTargetEntity().get(Keys.IS_SNEAKING).orElse(false)) { transportEntity(event.getTargetEntity(), location, Direction.DOWN); //Sneak is down } break; } } }
/** * @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); }
/** * @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 blank side of the sign opposite the text. In the case of a wall sign, * the block in this direction is the block to which the sign is * attached. This is also the direction a player would be facing when reading the sign; see {@link #getFront(Location)}. */ public static Direction getBack(Location<World> sign) { Direction front = getFront(sign); if (front == null) return Direction.NONE; return front.getOpposite(); }
public Location<World> getBackBlock() { return SignUtil.getBackBlock(this.block); }
checkFaces[1] = Direction.DOWN; switch (SignUtil.getFacing(sign.getLocation())) { case EAST: case WEST:
public static Location<World> getRightBlock(Location<World> sign) { return sign.getRelative(getRight(sign)); }
public static Location<World> getLeftBlock(Location<World> sign) { return sign.getRelative(getLeft(sign)); }