private static void platform(Location<World> center, BlockType type) { List<Location<World>> list = new ArrayList<>(); Location<World> south = center.getRelative(Direction.SOUTH); Location<World> north = center.getRelative(Direction.NORTH); Location<World> east = center.getRelative(Direction.EAST); Location<World> west = center.getRelative(Direction.WEST); Location<World> north2 = north.getRelative(Direction.NORTH); Location<World> south2 = south.getRelative(Direction.SOUTH); Location<World> east2 = east.getRelative(Direction.EAST); Location<World> west2 = west.getRelative(Direction.WEST); list.add(center); list.add(north); list.add(south); list.add(east); list.add(west); list.add(north.getRelative(Direction.EAST)); list.add(north.getRelative(Direction.WEST)); list.add(south.getRelative(Direction.EAST)); list.add(south.getRelative(Direction.WEST)); list.add(north2); list.add(north2.getRelative(Direction.EAST)); list.add(north2.getRelative(Direction.EAST).getRelative(Direction.EAST)); list.add(north2.getRelative(Direction.WEST)); list.add(north2.getRelative(Direction.WEST).getRelative(Direction.WEST)); list.add(south2); list.add(south2.getRelative(Direction.EAST)); list.add(south2.getRelative(Direction.EAST).getRelative(Direction.EAST)); list.add(south2.getRelative(Direction.WEST)); list.add(south2.getRelative(Direction.WEST).getRelative(Direction.WEST)); list.add(east2); list.add(east2.getRelative(Direction.NORTH)); list.add(east2.getRelative(Direction.SOUTH)); list.add(west2); list.add(west2.getRelative(Direction.NORTH)); list.add(west2.getRelative(Direction.SOUTH)); for (Location<World> location : list) { location.setBlock( Main.getGame() .getRegistry() .createBuilder(BlockState.Builder.class) .blockType(type) .build()); } }
@Override public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) { if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) { Direction back = SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN; Location baseBlock = block.getRelative(back); Location otherSide = getOtherEnd(block, back, maximumLength); if (otherSide == null) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build()); return true; } Location otherBase = otherSide.getRelative(back.getOpposite()); if (!baseBlock.getBlock().equals(otherBase.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Both ends must be the same material!").build()); return true; } int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default. Location left = baseBlock.getRelative(SignUtil.getLeft(block)); Location right = baseBlock.getRelative(SignUtil.getRight(block)); // Calculate left distance Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); while (true) { if (leftBlocks >= maximumWidth) break; 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; } } // Calculate right distance Location otherRight = otherBase.getRelative(SignUtil.getRight(block)); while (true) { if (rightBlocks >= maximumWidth) break; 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; } } baseBlock = baseBlock.getRelative(back); BlockState type = block.getRelative(back).getBlock(); if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState)) type = BlockTypes.AIR.getDefaultState(); while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) { baseBlock.setBlock(type); left = baseBlock.getRelative(SignUtil.getLeft(block)); for (int i = 0; i < leftBlocks; i++) { left.setBlock(type); left = left.getRelative(SignUtil.getLeft(block)); } right = baseBlock.getRelative(SignUtil.getRight(block)); for (int i = 0; i < rightBlocks; i++) { right.setBlock(type); right = right.getRelative(SignUtil.getRight(block)); } baseBlock = baseBlock.getRelative(back); } } else { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Door not activatable from here!").build()); return false; } return true; }