Exemplo n.º 1
0
 public void setCommandBlock(Block block) {
   castCommandBlock = block;
   if (castCommandBlock.getType() == Material.COMMAND) {
     BlockState commandData = castCommandBlock.getState();
     if (commandData != null && commandData instanceof CommandBlock) {
       CommandBlock commandBlock = ((CommandBlock) commandData);
       castCommand = commandBlock.getCommand();
       commandName = commandBlock.getName();
     }
     includeCommands = castCommand != null && castCommand.length() > 0;
   }
 }
Exemplo n.º 2
0
  protected boolean simulateBlock(int dx, int dy, int dz) {
    int x = center.getBlockX() + dx;
    int y = center.getBlockY() + dy;
    int z = center.getBlockZ() + dz;
    Block block = world.getBlockAt(x, y, z);
    if (!block.getChunk().isLoaded()) {
      block.getChunk().load();
      return false;
    }

    Material blockMaterial = block.getType();
    if (birthMaterial.is(block)) {
      int distanceSquared =
          liveRangeSquared > 0 || includeCommands
              ? (int) Math.ceil(block.getLocation().distanceSquared(castCommandBlock.getLocation()))
              : 0;

      if (liveRangeSquared <= 0 || distanceSquared <= liveRangeSquared) {
        if (diagonalLiveCounts.size() > 0) {
          int faceNeighborCount = getFaceNeighborCount(block, birthMaterial, includeCommands);
          int diagonalNeighborCount =
              getDiagonalNeighborCount(block, birthMaterial, includeCommands);
          if (faceNeighborCount >= liveCounts.size()
              || !liveCounts.get(faceNeighborCount)
              || diagonalNeighborCount >= diagonalLiveCounts.size()
              || !diagonalLiveCounts.get(diagonalNeighborCount)) {
            killBlock(block);
          } else {
            checkForPotentialCommand(block, distanceSquared);
          }
        } else {
          int neighborCount = getNeighborCount(block, birthMaterial, includeCommands);
          if (neighborCount >= liveCounts.size() || !liveCounts.get(neighborCount)) {
            killBlock(block);
          } else {
            checkForPotentialCommand(block, distanceSquared);
          }
        }
      } else {
        killBlock(block);
      }
    } else if (blockMaterial == deathMaterial) {
      int distanceSquared =
          birthRangeSquared > 0 || includeCommands
              ? (int) Math.ceil(block.getLocation().distanceSquared(castCommandBlock.getLocation()))
              : 0;

      if (birthRangeSquared <= 0 || distanceSquared <= birthRangeSquared) {
        if (diagonalBirthCounts.size() > 0) {
          int faceNeighborCount = getFaceNeighborCount(block, birthMaterial, includeCommands);
          int diagonalNeighborCount =
              getDiagonalNeighborCount(block, birthMaterial, includeCommands);
          if (faceNeighborCount < birthCounts.size()
              && birthCounts.get(faceNeighborCount)
              && diagonalNeighborCount < diagonalBirthCounts.size()
              && diagonalBirthCounts.get(diagonalNeighborCount)) {
            birthBlock(block);
            checkForPotentialCommand(block, distanceSquared);
          }
        } else {
          int neighborCount = getNeighborCount(block, birthMaterial, includeCommands);
          if (neighborCount < birthCounts.size() && birthCounts.get(neighborCount)) {
            birthBlock(block);
            checkForPotentialCommand(block, distanceSquared);
          }
        }
      }
    } else if (includeCommands
        && blockMaterial == Material.COMMAND
        && commandName != null
        && commandName.length() > 1) {
      // Absorb nearby commands of the same name.
      BlockState commandData = block.getState();
      if (commandData != null && commandData instanceof CommandBlock) {
        CommandBlock commandBlock = ((CommandBlock) commandData);
        if (commandBlock.getName().equals(commandName)) {
          block.setType(deathMaterial);
          if (DEBUG) {
            controller.getLogger().info("CONSUMED clone at " + block.getLocation().toVector());
          }
        }
      }
    }

    return true;
  }