Пример #1
0
  private void erosion(final SnipeData v) {
    if (this.reverse) {
      int temp = this.erodeFace;
      this.erodeFace = this.fillFace;
      this.fillFace = temp;
      temp = this.erodeRecursion;
      this.erodeRecursion = this.fillRecursion;
      this.fillRecursion = temp;
    }
    final Undo h = new Undo(this.getTargetBlock().getWorld().getName());

    if (this.erodeFace >= 0 && this.erodeFace <= 6) {
      for (int er = 0; er < this.erodeRecursion; er++) {
        this.getMatrix();

        final int derp = this.bsize + 1;

        final double bpow = Math.pow(this.bsize + this.trueCircle, 2);
        for (int z = 1; z < this.snap.length - 1; z++) {

          final double zpow = Math.pow(z - derp, 2);
          for (int x = 1; x < this.snap.length - 1; x++) {

            final double xpow = Math.pow(x - derp, 2);
            for (int y = 1; y < this.snap.length - 1; y++) {

              if (((xpow + Math.pow(y - derp, 2) + zpow) <= bpow)) {
                if (this.erode(x, y, z)) {
                  this.snap[x][y][z].b.setTypeId(0);
                }
              }
            }
          }
        }
      }
    }
    if (this.fillFace >= 0 && this.fillFace <= 6) {
      for (int fr = 0; fr < this.fillRecursion; fr++) {
        this.getMatrix();

        final int derp = this.bsize + 1;

        final double bpow = Math.pow(this.bsize + 0.5, 2);
        for (int z = 1; z < this.snap.length - 1; z++) {

          final double zpow = Math.pow(z - derp, 2);
          for (int x = 1; x < this.snap.length - 1; x++) {

            final double xpow = Math.pow(x - derp, 2);
            for (int y = 1; y < this.snap.length - 1; y++) {

              if (((xpow + Math.pow(y - derp, 2) + zpow) <= bpow)) {
                if (this.fill(x, y, z)) {
                  this.snap[x][y][z].b.setTypeId(this.snap[x][y][z].id);
                }
              }
            }
          }
        }
      }
    }

    for (int x = 0; x < this.firstSnap.length; x++) {
      for (int y = 0; y < this.firstSnap.length; y++) {
        for (int z = 0; z < this.firstSnap.length; z++) {
          final eBlock e = this.firstSnap[x][y][z];
          if (e.i != e.b.getTypeId()) {
            h.put(e.b);
          }
        }
      }
    }

    v.storeUndo(h);
    if (this
        .reverse) { // if you dont put it back where it was, powder flips back and forth from fill
                    // to erode each time
      int temp = this.erodeFace;
      this.erodeFace = this.fillFace;
      this.fillFace = temp;
      temp = this.erodeRecursion;
      this.erodeRecursion = this.fillRecursion;
      this.fillRecursion = temp;
    }
  }
  private boolean set(final Block bl, final SnipeData v) {
    if (this.block == null) {
      this.block = bl;
      return true;
    } else {
      if (!this.block.getWorld().getName().equals(bl.getWorld().getName())) {
        v.sendMessage(ChatColor.RED + "You selected points in different worlds!");
        this.block = null;
        return true;
      }

      final int _voxelMaterialId = v.getVoxelId();
      final int _voxelReplaceMaterialId = v.getReplaceId();

      final int _lowx = (this.block.getX() <= bl.getX()) ? this.block.getX() : bl.getX();
      final int _lowy = (this.block.getY() <= bl.getY()) ? this.block.getY() : bl.getY();
      final int _lowz = (this.block.getZ() <= bl.getZ()) ? this.block.getZ() : bl.getZ();
      final int _highx = (this.block.getX() >= bl.getX()) ? this.block.getX() : bl.getX();
      final int _highy = (this.block.getY() >= bl.getY()) ? this.block.getY() : bl.getY();
      final int _highz = (this.block.getZ() >= bl.getZ()) ? this.block.getZ() : bl.getZ();

      if (Math.abs(_highx - _lowx) * Math.abs(_highz - _lowz) * Math.abs(_highy - _lowy)
          > MAX_SIZE) {
        v.sendMessage(
            ChatColor.RED
                + "Selection size above hardcoded limit, please use a smaller selection.");
      } else {
        final ArrayList<Block> _blocks =
            new ArrayList<Block>(
                ((Math.abs(_highx - _lowx) * Math.abs(_highz - _lowz) * Math.abs(_highy - _lowy))
                    / 2));
        for (int _y = _lowy; _y <= _highy; _y++) {
          for (int _x = _lowx; _x <= _highx; _x++) {
            for (int _z = _lowz; _z <= _highz; _z++) {
              if (this.getWorld().getBlockTypeIdAt(_x, _y, _z) == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x + 1, _y, _z)
                  == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x - 1, _y, _z)
                  == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x, _y, _z + 1)
                  == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x, _y, _z - 1)
                  == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x, _y + 1, _z)
                  == _voxelReplaceMaterialId) {
                continue;
              } else if (this.getWorld().getBlockTypeIdAt(_x, _y - 1, _z)
                  == _voxelReplaceMaterialId) {
                continue;
              } else {
                _blocks.add(this.getWorld().getBlockAt(_x, _y, _z));
              }
            }
          }
        }

        final Undo _undo = new Undo(this.getTargetBlock().getWorld().getName());
        for (final Block _block : _blocks) {
          if (_block.getTypeId() != _voxelMaterialId) {
            _undo.put(_block);
            _block.setTypeId(_voxelMaterialId);
          }
        }
        v.storeUndo(_undo);
        v.sendMessage(ChatColor.AQUA + "Shell complete.");
      }

      this.block = null;
      return false;
    }
  }