Java源码示例:com.sk89q.worldedit.Vector2D

示例1
@Command(
        aliases = {"chunkinfo"},
        usage = "",
        desc = "Get information about the chunk that you are inside",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.chunkinfo")
public void chunkInfo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    Vector pos = player.getBlockIn();
    int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
    int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);

    String folder1 = Integer.toString(MathUtils.divisorMod(chunkX, 64), 36);
    String folder2 = Integer.toString(MathUtils.divisorMod(chunkZ, 64), 36);
    String filename = "c." + Integer.toString(chunkX, 36)
            + "." + Integer.toString(chunkZ, 36) + ".dat";

    player.print(BBC.getPrefix() + "Chunk: " + chunkX + ", " + chunkZ);
    player.print(BBC.getPrefix() + "Old format: " + folder1 + "/" + folder2 + "/" + filename);
    player.print(BBC.getPrefix() + "McRegion: region/" + McRegionChunkStore.getFilename(
            new Vector2D(chunkX, chunkZ)));
}
 
示例2
@Override
public void apply(Element applyTo, CylinderRegion region) {
	Vector center = region.getCenter();
	Vector2D radius = region.getRadius();
	int minY = region.getMinimumY();
	int maxY = region.getMaximumY();
	
	Element centerElement = applyTo.addElement("center");
	centerElement.addElement("x").addText(String.valueOf(center.getBlockX()));
	centerElement.addElement("y").addText(String.valueOf(center.getBlockY()));
	centerElement.addElement("z").addText(String.valueOf(center.getBlockZ()));
	
	Element radiusElement = applyTo.addElement("radius");
	radiusElement.addElement("x").addText(String.valueOf(radius.getBlockX()));
	radiusElement.addElement("z").addText(String.valueOf(radius.getBlockZ()));
	
	applyTo.addElement("minY").addText(String.valueOf(minY));
	applyTo.addElement("maxY").addText(String.valueOf(maxY));
}
 
示例3
@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);
	}
}
 
示例4
@Override
public CylinderRegion asRegion(Map<String, Tag> tags) {
	ListTag centerTag = (ListTag) tags.get("center");
	ListTag radiusTag = (ListTag) tags.get("radius");
	
	int centerX = centerTag.getInt(0);
	int centerY = centerTag.getInt(1);
	int centerZ = centerTag.getInt(2);
	
	int pos2X = radiusTag.getInt(0);
	int pos2Z = radiusTag.getInt(1);
	
	Vector center = new Vector(centerX, centerY, centerZ);
	Vector2D radius = new Vector2D(pos2X, pos2Z);
	int minY = (int) tags.get("minY").getValue();
	int maxY = (int) tags.get("maxY").getValue();
	
	return new CylinderRegion(center, radius, minY, maxY);
}
 
示例5
@Override
public Set<Vector2D> getChunks() {
    final Set<Vector2D> chunks = new HashSet<Vector2D>();

    final Vector min = getMinimumPoint();
    final Vector max = getMaximumPoint();
    final int centerY = getCenter().getBlockY();

    for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
        for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
            if (!contains(new BlockVector(x, centerY, z))) {
                continue;
            }

            chunks.add(new BlockVector2D(
                    x >> ChunkStore.CHUNK_SHIFTS,
                    z >> ChunkStore.CHUNK_SHIFTS
            ));
        }
    }

    return chunks;
}
 
示例6
@Override
public CylinderRegion asRegion(Element container) {
	Element centerElement = container.element("center");
	Element radiusElement = container.element("radius");
	Element minYElement = container.element("minY");
	Element maxYElement = container.element("maxY");
	
	int cx = Integer.parseInt(centerElement.elementText("x"));
	int cy = Integer.parseInt(centerElement.elementText("y"));
	int cz = Integer.parseInt(centerElement.elementText("z"));
	
	int rx = Integer.parseInt(radiusElement.elementText("x"));
	int rz = Integer.parseInt(radiusElement.elementText("z"));
	
	int minY = Integer.parseInt(minYElement.getText());
	int maxY = Integer.parseInt(maxYElement.getText());
	
	Vector center = new Vector(cx, cy, cz);
	Vector2D radius = new Vector2D(rx, rz);
	
	return new CylinderRegion(center, radius, minY, maxY);
}
 
示例7
/**
 * Paste structure at the provided position on the curve. The position will not be position-corrected
 * but will be passed directly to the interpolation algorithm.
 * @param position The position on the curve. Must be between 0.0 and 1.0 (both inclusive)
 * @return         The amount of blocks that have been changed
 * @throws MaxChangedBlocksException Thrown by WorldEdit if the limit of block changes for the {@link EditSession} has been reached
 */
public int pastePositionDirect(double position) throws MaxChangedBlocksException {
    Preconditions.checkArgument(position >= 0);
    Preconditions.checkArgument(position <= 1);

    // Calculate position from spline
    Vector target = interpolation.getPosition(position);
    Vector offset = target.subtract(target.round());
    target = target.subtract(offset);

    // Calculate rotation from spline

    Vector deriv = interpolation.get1stDerivative(position);
    Vector2D deriv2D = new Vector2D(deriv.getX(), deriv.getZ()).normalize();
    double angle = Math.toDegrees(
            Math.atan2(direction.getZ(), direction.getX()) - Math.atan2(deriv2D.getZ(), deriv2D.getX())
    );

    return pasteBlocks(target, offset, angle);
}
 
示例8
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    if (manager.isPlayerIgnoringWELimit(player)) {
        return extent.setBiome(position, biome);
    } else {
        Location loc = new Location(player.getWorld(), position.getX(), 0, position.getZ());
        Plot plot = manager.getPlot(loc);
        if (plot != null) {
            if (plot.getOwnerId().equals(player.getUniqueId())) {
                return extent.setBiome(position, biome);
            }
            Optional<Plot.AccessLevel> member = plot.isMember(actor.getUniqueId());
            if (member.isPresent()) {
                return !(member.get().equals(Plot.AccessLevel.TRUSTED) && !api.getServerBridge().getOfflinePlayer(plot.getOwnerId()).isOnline())
                        && extent.setBiome(position, biome);
            }
        }
        return false;
    }
}
 
示例9
/**
 * Gets a type from a {@link ArgumentStack}.
 *
 * @param context the context
 * @return the requested type
 * @throws ParameterException on error
 */
@BindingMatch(type = Vector2D.class,
        behavior = BindingBehavior.CONSUMES,
        consumedCount = 1,
        provideModifiers = true)
public Vector2D getVector2D(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
    String radiusString = context.next();
    String[] radii = radiusString.split(",");
    final double radiusX, radiusZ;
    switch (radii.length) {
        case 1:
            radiusX = radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
            break;

        case 2:
            radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
            radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
            break;

        default:
            throw new ParameterException("You must either specify 1 or 2 radius values.");
    }
    return new Vector2D(radiusX, radiusZ);
}
 
示例10
/**
 * Negate the given mask.
 *
 * @param mask the mask
 * @return a new mask
 */
public static Mask2D negate(final Mask2D mask) {
    if (mask instanceof AlwaysTrue) {
        return ALWAYS_FALSE;
    } else if (mask instanceof AlwaysFalse) {
        return ALWAYS_TRUE;
    }

    checkNotNull(mask);
    return new AbstractMask2D() {
        @Override
        public boolean test(Vector2D vector) {
            return !mask.test(vector);
        }
    };
}
 
示例11
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);
        }
    }
}
 
示例12
@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;
}
 
示例13
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    if (region.contains(position.getBlockX(), position.getBlockZ())) {
        return super.setBiome(position, biome);
    }
    return false;
}
 
示例14
@Override
public Iterable<Vector2D> asFlatRegion() {
    return new Iterable<Vector2D>() {
        @Override
        public Iterator<Vector2D> iterator() {
            return new FlatRegionIterator(CylinderRegion.this);
        }
    };
}
 
示例15
@Override
public BaseBiome getBiome(Vector2D position) {
    mutable.mutX(position.getBlockX());
    mutable.mutZ(position.getBlockZ());
    mutable.mutY(0);
    return super.getBiome(getPos(mutable).toVector2D());
}
 
示例16
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    mutable.mutX(position.getBlockX());
    mutable.mutZ(position.getBlockZ());
    mutable.mutY(0);
    return super.setBiome(getPos(mutable).toVector2D(), biome);
}
 
示例17
@Override
public BaseBiome getBiome(Vector2D position) {
    if (position.getX() == bx && position.getZ() == bz) {
        return biome;
    }
    return super.getBiome(position);
}
 
示例18
@Override
public BaseBiome getBiome(Vector2D position) {
    mutable.mutX(position.getBlockX());
    mutable.mutZ(position.getBlockZ());
    mutable.mutY(0);
    return super.getBiome(getPos(mutable).toVector2D());
}
 
示例19
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    mutable.mutX(position.getBlockX());
    mutable.mutZ(position.getBlockZ());
    mutable.mutY(0);
    return super.setBiome(getPos(mutable).toVector2D(), biome);
}
 
示例20
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    if (!contains(position)) {
        if (!limit.MAX_FAILS()) {
            WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
        }
        return false;
    }
    return super.setBiome(position, biome);
}
 
示例21
@Override
public BaseBiome getBiome(Vector2D position) {
    if (!contains(position)) {
        if (!limit.MAX_FAILS()) {
            WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
        }
        return EditSession.nullBiome;
    }
    return super.getBiome(position);
}
 
示例22
/**
 * Create a new selector.
 *
 * @param world the world
 * @param center the center
 * @param radius the radius
 * @param minY the minimum Y
 * @param maxY the maximum Y
 */
public CylinderRegionSelector(@Nullable World world, Vector2D center, Vector2D radius, int minY, int maxY) {
    this(world);

    region.setCenter(center);
    region.setRadius(radius);

    region.setMinimumY(Math.min(minY, maxY));
    region.setMaximumY(Math.max(minY, maxY));
}
 
示例23
@Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) {
    if (!limit.MAX_CHANGES()) {
        WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
        return false;
    }
    return super.setBiome(position, biome);
}
 
示例24
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    boolean result = false;
    Vector pos = getPos(position.getBlockX(), 0, position.getBlockZ());
    double sx = pos.getX();
    double sz = pos.getZ();
    double ex = pos.getX() + dx;
    double ez = pos.getZ() + dz;
    for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) {
        for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) {
            result |= super.setBiome(pos.toVector2D(), biome);
        }
    }
    return result;
}
 
示例25
@Command(
        aliases = {"listchunks"},
        usage = "",
        desc = "List chunks that your selection includes",
        min = 0,
        max = 0
)
@CommandPermissions("worldedit.listchunks")
public void listChunks(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();

    for (Vector2D chunk : chunks) {
        player.print(BBC.getPrefix() + LegacyChunkStore.getFilename(chunk));
    }
}
 
示例26
@Override
public Iterator<Vector2D> iterator() {
    return new Iterator<Vector2D>() {
        int index = set.nextSetBit(0);
        int previous = -1;

        @Override
        public void remove() {
            set.clear(previous);
        }

        @Override
        public boolean hasNext() {
            return index != -1;
        }

        @Override
        public Vector2D next() {
            if (index != -1) {
                int x = MathMan.unpairSearchCoordsX(index);
                int y = MathMan.unpairSearchCoordsY(index);
                mutable.setComponents(x, y);
                previous = index;
                index = set.nextSetBit(index + 1);
                return mutable;
            }
            return null;
        }
    };
}
 
示例27
@Override
public boolean remove(Object o) {
    if (o instanceof Vector2D) {
        Vector2D v = (Vector2D) o;
        return remove(v.getBlockX(), v.getBlockZ());
    }
    return false;
}
 
示例28
@Override
public boolean addAll(Collection<? extends Vector2D> c) {
    boolean result = false;
    for (Vector2D v : c) {
        result |= add(v);
    }
    return result;
}
 
示例29
@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);
        }
    }
}
 
示例30
private Vector2D calculateChanges2D(Vector... changes) {
    Vector2D total = new Vector2D();
    for (Vector change : changes) {
        total = total.add(change.toVector2D().positive());
    }

    return total.divide(2).floor();
}