Java Code Examples for com.sk89q.worldedit.Vector2D#getBlockZ()

The following examples show how to use com.sk89q.worldedit.Vector2D#getBlockZ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CylinderSpawnpointGenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void generateSpawnpoints(CylinderRegion region, World world, List<Location> spawnpoints, int n) {
	Vector center = region.getCenter();
	Vector2D radius = region.getRadius();
	int radx = radius.getBlockX();
	int radz = radius.getBlockZ();
	
	int y = region.getMaximumY() + 1;
	
	for (int i = 0; i < n; i++) {
		double a = Math.random() * 2 * Math.PI;
		double randomradx = Math.random() * radx;
		double randomradz = Math.random() * radz;
		
		int rx = (int) (randomradx * Math.sin(a));
		int rz = (int) (randomradz * Math.cos(a));
		
		int px = center.getBlockX() + rx;
		int pz = center.getBlockZ() + rz;
		
		Location location = new Location(world, px, y, pz);
		spawnpoints.add(location);
	}
}
 
Example 2
Source File: CuboidRegionFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void add(Vector2D pos1, Vector2D pos2) {
    int ccx1 = pos1.getBlockX() >> 9;
    int ccz1 = pos1.getBlockZ() >> 9;
    int ccx2 = pos2.getBlockX() >> 9;
    int ccz2 = pos2.getBlockZ() >> 9;
    for (int x = ccx1; x <= ccx2; x++) {
        for (int z = ccz1; z <= ccz2; z++) {
            if (!occupiedRegions.containsKey(x, z)) {
                occupiedRegions.add(x, z);
                int bcx = x << 5;
                int bcz = z << 5;
                int tcx = bcx + 32;
                int tcz = bcz + 32;
                for (int cz = bcz; cz < tcz; cz++) {
                    for (int cx = bcx; cx < tcx; cx++) {
                        unoccupiedChunks.add(cx, cz);
                    }
                }
            }
        }
    }
    int cx1 = pos1.getBlockX() >> 4;
    int cz1 = pos1.getBlockZ() >> 4;
    int cx2 = pos2.getBlockX() >> 4;
    int cz2 = pos2.getBlockZ() >> 4;
    for (int cz = cz1; cz <= cz2; cz++) {
        for (int cx = cx1; cx <= cx2; cx++) {
            unoccupiedChunks.remove(cx, cz);
        }
    }
}
 
Example 3
Source File: SurfaceRegionFunction.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Vector2D position) throws WorldEditException {
    int x = position.getBlockX();
    int z = position.getBlockZ();
    int layer = extent.getNearestSurfaceTerrainBlock(x, z, lastY, minY, maxY, false);
    if (layer != -1) {
        lastY = layer;
        return function.apply(mutable.setComponents(x, layer, z));
    }
    return false;
}
 
Example 4
Source File: CavesGen.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void generateChunk(Vector2D adjacentChunk, Vector2D originChunk, Extent chunk) throws WorldEditException {
    PseudoRandom random = getRandom();
    int i = random.nextInt(random.nextInt(random.nextInt(this.caveFrequency) + 1) + 1);
    if (this.evenCaveDistribution)
        i = this.caveFrequency;
    if (random.nextInt(100) >= this.caveRarity)
        i = 0;

    for (int j = 0; j < i; j++) {
        double x = (adjacentChunk.getBlockX() << 4) + random.nextInt(16);

        double y;

        if (this.evenCaveDistribution)
            y = random.nextInt(this.caveMinAltitude, this.caveMaxAltitude);
        else
            y = random.nextInt(random.nextInt(this.caveMaxAltitude - this.caveMinAltitude + 1) + 1) + this.caveMinAltitude;

        double z = (adjacentChunk.getBlockZ() << 4) + random.nextInt(16);

        int count = this.caveSystemFrequency;
        boolean largeCaveSpawned = false;
        if (random.nextInt(100) <= this.individualCaveRarity) {
            generateLargeCaveNode(random.nextLong(), originChunk, chunk, x, y, z);
            largeCaveSpawned = true;
        }

        if ((largeCaveSpawned) || (random.nextInt(100) <= this.caveSystemPocketChance - 1)) {
            count += random.nextInt(this.caveSystemPocketMinSize, this.caveSystemPocketMaxSize);
        }
        while (count > 0) {
            count--;
            double f1 = random.nextDouble() * 3.141593F * 2.0F;
            double f2 = (random.nextDouble() - 0.5F) * 2.0F / 8.0F;
            double f3 = random.nextDouble() * 2.0F + random.nextDouble();
            generateCaveNode(random.nextLong(), originChunk, chunk, x, y, z, f3, f1, f2, 0, 0, 1.0D);
        }
    }
}
 
Example 5
Source File: GenBase.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void generate(Vector2D chunkPos, Extent chunk) throws WorldEditException {
    int i = this.checkAreaSize;
    int chunkX = chunkPos.getBlockX();
    int chunkZ = chunkPos.getBlockZ();

    for (int x = chunkX - i; x <= chunkX + i; x++) {
        mutable.mutX(x);
        for (int z = chunkZ - i; z <= chunkZ + i; z++) {
            mutable.mutZ(z);
            this.random.setSeed(worldSeed1 * x ^ worldSeed2 * z ^ seed);
            generateChunk(mutable, chunkPos, chunk);
        }
    }
}
 
Example 6
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    int x = position.getBlockX() - mx;
    int z = position.getBlockZ() - mz;
    IMP.setBiome(x, z, biome.getId());
    return true;
}
 
Example 7
Source File: CylinderRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector2D calculateDiff2D(Vector... changes) throws RegionOperationException {
    Vector2D diff = new Vector2D();
    for (Vector change : changes) {
        diff = diff.add(change.toVector2D());
    }

    if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
        throw new RegionOperationException("Cylinders changes must be even for each horizontal dimensions.");
    }

    return diff.divide(2).floor();
}
 
Example 8
Source File: RandomOffsetTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean setBiome(Vector2D pos, BaseBiome biome) {
    int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx;
    int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz;
    return getExtent().setBiome(mutable.setComponents(x, z), biome);
}
 
Example 9
Source File: Fast2DIterator.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Iterator<Vector2D> iterator() {
    if (queue == null || Settings.IMP.QUEUE.PRELOAD_CHUNKS <= 1) {
        return (Iterator<Vector2D>) iterable.iterator();
    }
    return new Iterator<Vector2D>() {
        Iterator<? extends Vector2D> trailIter = iterable.iterator();
        Iterator<? extends Vector2D> leadIter = iterable.iterator();
        int lastTrailChunkX = Integer.MIN_VALUE;
        int lastTrailChunkZ = Integer.MIN_VALUE;
        int lastLeadChunkX = Integer.MIN_VALUE;
        int lastLeadChunkZ = Integer.MIN_VALUE;
        int loadingTarget = Settings.IMP.QUEUE.PRELOAD_CHUNKS;
        int cx, cz;

        @Override
        public void remove() {
            trailIter.remove();
        }

        @Override
        public boolean hasNext() {
            return trailIter.hasNext();
        }

        @Override
        public Vector2D next() {
            Vector2D pt = trailIter.next();
            if (lastTrailChunkX != (lastTrailChunkX = pt.getBlockX() >> 4) || lastTrailChunkZ != (lastTrailChunkZ = pt.getBlockZ() >> 4)) {
                if (leadIter.hasNext()) {
                    try {
                        int amount;
                        if (lastLeadChunkX == Integer.MIN_VALUE) {
                            lastLeadChunkX = cx;
                            lastLeadChunkZ = cz;
                            amount = loadingTarget;
                        } else {
                            amount = 1;
                        }
                        for (int count = 0; count < amount; ) {
                            Vector2D v = leadIter.next();
                            int vcx = v.getBlockX() >> 4;
                            int vcz = v.getBlockZ() >> 4;
                            if (vcx != lastLeadChunkX || vcz != lastLeadChunkZ) {
                                lastLeadChunkX = vcx;
                                lastLeadChunkZ = vcz;
                                queue.queueChunkLoad(vcx, vcz);
                                count++;
                            }
                        }
                    } catch (Throwable ignore) {
                    }
                }
            }
            return pt;
        }
    };
}
 
Example 10
Source File: HeightMap.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public HeightMap(EditSession session, Region region, boolean naturalOnly, boolean layers) {
    checkNotNull(session);
    checkNotNull(region);

    this.session = session;
    this.region = region;

    this.width = region.getWidth();
    this.height = region.getLength();

    this.layers = layers;

    int minX = region.getMinimumPoint().getBlockX();
    int minY = region.getMinimumPoint().getBlockY();
    int minZ = region.getMinimumPoint().getBlockZ();
    int maxY = region.getMaximumPoint().getBlockY();

    data = new int[width * height];
    invalid = new boolean[data.length];

    if (layers) {
        Vector min = region.getMinimumPoint();
        Vector max = region.getMaximumPoint();
        int bx = min.getBlockX();
        int bz = min.getBlockZ();
        Iterable<Vector2D> flat = Regions.asFlatRegion(region).asFlatRegion();
        Iterator<Vector2D> iter = new Fast2DIterator(flat, session).iterator();
        int layer = 0;
        MutableBlockVector mutable = new MutableBlockVector();
        while (iter.hasNext()) {
            Vector2D pos = iter.next();
            int x = pos.getBlockX();
            int z = pos.getBlockZ();
            layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY);
            data[(z - bz) * width + (x - bx)] = layer;
        }
    } else {
        // Store current heightmap data
        int index = 0;
        if (naturalOnly) {
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    data[index] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY, naturalOnly);
                }
            }
        } else {
            int yTmp = 255;
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
                    switch (yTmp) {
                        case Integer.MIN_VALUE:
                            yTmp = minY;
                            invalid[index] = true;
                            break;
                        case Integer.MAX_VALUE:
                            yTmp = maxY;
                            invalid[index] = true;
                            break;
                    }
                    data[index] = yTmp;
                }
            }
        }
    }
}
 
Example 11
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseBiome getBiome(Vector2D position) {
    int x = position.getBlockX() - mx;
    int z = position.getBlockZ() - mz;
    return IMP.getBiome(x, z);
}