@Override
  public void simulateBlockMine(Vector pt) {
    BaseBlock block = getLazyBlock(pt);
    BaseItemStack stack = BlockType.getBlockDrop(block.getId(), (short) block.getData());

    if (stack != null) {
      final int amount = stack.getAmount();
      if (amount > 1) {
        dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
      } else {
        dropItem(pt, stack, amount);
      }
    }

    try {
      setBlock(pt, new BaseBlock(BlockID.AIR));
    } catch (WorldEditException e) {
      throw new RuntimeException(e);
    }
  }
  @SuppressWarnings({"deprecation"})
  @Override
  public MaterialAndData getBlock(Vector v) {
    int x = v.getBlockX() + center.getBlockX();
    int y = v.getBlockY() + center.getBlockY();
    int z = v.getBlockZ() + center.getBlockZ();

    try {
      if (x < 0
          || x >= size.getBlockZ()
          || y < 0
          || y >= size.getBlockY()
          || z < 0
          || z >= size.getBlockZ()) {
        return null;
      }

      com.sk89q.worldedit.Vector vector = new com.sk89q.worldedit.Vector(x, y, z);
      BaseBlock baseBlock = weSchematic.getBlock(vector);
      Material material = Material.getMaterial(baseBlock.getId());

      int materialData = baseBlock.getData();
      MaterialAndData blockData = new MaterialAndData(material, (byte) materialData);

      // Note.. we don't actually get a SignBlock here, for some reason.
      // May have something to do with loading schematics not actually supporting sign
      // text, it doesn't work with //schematic and //paste, either.
      // It looks like //paste works in a dev build of WE, but it still doesn't give me the blocks
      // Looking at WE's code, it seems like the part that's needed is commented out... ??
      if (material == Material.SIGN_POST || material == Material.WALL_SIGN) {
        try {
          if (baseBlock.hasNbtData()) {
            SignBlock signBlock = new SignBlock(material.getId(), materialData);
            CompoundTag nbtData = baseBlock.getNbtData();
            signBlock.setNbtData(nbtData);
            blockData.setSignLines(signBlock.getText());
          }
        } catch (Throwable ex) {
          ex.printStackTrace();
        }
      } else if (material == Material.COMMAND) {
        try {
          if (baseBlock.hasNbtData()) {
            CompoundTag nbtRoot = baseBlock.getNbtData();
            Map<String, Tag> rootValues = nbtRoot.getValue();
            if (rootValues.containsKey("Command")) {
              Object commandValue = rootValues.get("Command").getValue();
              blockData.setCommandLine((String) commandValue);
            }
            if (rootValues.containsKey("CustomName")) {
              Object nameValue = rootValues.get("CustomName").getValue();
              blockData.setCustomName((String) nameValue);
            }
          }
        } catch (Throwable ex) {
          ex.printStackTrace();
        }
      } else if (material == Material.CHEST) {
        try {
          if (baseBlock.hasNbtData()) {
            ChestBlock chestBlock = new ChestBlock(materialData);
            CompoundTag nbtRoot = baseBlock.getNbtData();
            chestBlock.setNbtData(nbtRoot);
            BaseItemStack[] items = chestBlock.getItems();

            if (items != null && items.length > 0) {
              ItemStack[] contents = new ItemStack[items.length];
              for (int i = 0; i < items.length; i++) {
                if (items[i] != null) {
                  Material itemMaterial = Material.getMaterial(items[i].getType());

                  // Bukkit.getLogger().info("Item from chest: " + itemMaterial + " at " + i + " / "
                  // + contents.length);

                  short itemData = items[i].getData();
                  int itemAmount = items[i].getAmount();
                  ItemStack newStack = new ItemStack(itemMaterial, itemAmount, itemData);

                  Map<Integer, Integer> enchantments = items[i].getEnchantments();
                  if (enchantments != null && enchantments.size() > 0) {
                    for (Entry<Integer, Integer> enchantment : enchantments.entrySet()) {
                      try {
                        Enchantment enchantmentType = Enchantment.getById(enchantment.getKey());
                        newStack.addEnchantment(enchantmentType, enchantment.getValue());
                      } catch (Exception ex) {
                        // This seems to happen a lot .. like on potions especially.
                        ex.printStackTrace();
                      }
                    }
                  }
                  contents[i] = newStack;
                }
              }
              blockData.setInventoryContents(contents);
            }
          }
        } catch (Throwable ex) {
          ex.printStackTrace();
        }
      }

      return blockData;
    } catch (ArrayIndexOutOfBoundsException ex) {
      // TODO: Figure out why this still happens, even with the size check
    } catch (Throwable ex) {
      ex.printStackTrace();
    }

    return null;
  }
  @Command(
      aliases = {"/set"},
      usage = "[pattern]",
      desc = "Set all blocks within selection",
      min = 1,
      max = 1)
  @CommandPermissions("worldedit.region.set")
  @Logging(REGION)
  public void set(
      Player player,
      EditSession editSession,
      LocalSession session,
      @Selection Region selection,
      Pattern to)
      throws WorldEditException {
    if (selection instanceof CuboidRegion
        && editSession.hasFastMode()
        && to instanceof BlockPattern) {
      try {
        CuboidRegion cuboid = (CuboidRegion) selection;
        RegionWrapper current =
            new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
        BaseBlock block = ((BlockPattern) to).getBlock();
        final FaweQueue queue = editSession.getQueue();
        final int minY = cuboid.getMinimumY();
        final int maxY = cuboid.getMaximumY();

        final int id = block.getId();
        final byte data = (byte) block.getData();
        final FaweChunk<?> fc = queue.getFaweChunk(0, 0);
        fc.fillCuboid(0, 15, minY, maxY, 0, 15, id, data);
        fc.optimize();

        int bcx = (current.minX) >> 4;
        int bcz = (current.minZ) >> 4;

        int tcx = (current.maxX) >> 4;
        int tcz = (current.maxZ) >> 4;
        // [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
        MainUtil.chunkTaskSync(
            current,
            new RunnableVal<int[]>() {
              @Override
              public void run(int[] value) {
                FaweChunk newChunk;
                if (value[6] == 0) {
                  newChunk = fc.copy(true);
                  newChunk.setLoc(queue, value[0], value[1]);
                } else {
                  int bx = value[2] & 15;
                  int tx = value[4] & 15;
                  int bz = value[3] & 15;
                  int tz = value[5] & 15;
                  if (bx == 0 && tx == 15 && bz == 0 && tz == 15) {
                    newChunk = fc.copy(true);
                    newChunk.setLoc(queue, value[0], value[1]);
                  } else {
                    newChunk = queue.getFaweChunk(value[0], value[1]);
                    newChunk.fillCuboid(
                        value[2] & 15,
                        value[4] & 15,
                        minY,
                        maxY,
                        value[3] & 15,
                        value[5] & 15,
                        id,
                        data);
                  }
                }
                newChunk.addToQueue();
              }
            });
        queue.enqueue();
        long start = System.currentTimeMillis();
        BBC.OPERATION.send(player, BBC.VISITOR_BLOCK.format(cuboid.getArea()));
        queue.flush();
        BBC.ACTION_COMPLETE.send(player, (System.currentTimeMillis() - start) / 1000d);
        return;
      } catch (Throwable e) {
        MainUtil.handleError(e);
      }
    }
    int affected = editSession.setBlocks(selection, Patterns.wrap(to));
    BBC.OPERATION.send(player, affected);
  }