com.sk89q.worldedit.BlockVector2D Java Examples

The following examples show how to use com.sk89q.worldedit.BlockVector2D. 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: Polygonal2DRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Map<String, Tag> tags, Polygonal2DRegion region) {
	List<BlockVector2D> points = region.getPoints();
	int minY = region.getMinimumY();
	int maxY = region.getMaximumY();
	
	List<ListTag> pointList = Lists.newArrayList();
	for (BlockVector2D vector : points) {
		List<IntTag> vectorList = Lists.newArrayList();
		vectorList.add(new IntTag(vector.getBlockX()));
		vectorList.add(new IntTag(vector.getBlockZ()));
		
		ListTag vectorListTag = new ListTag(IntTag.class, vectorList);
		pointList.add(vectorListTag);
	}
	
	ListTag pointListTag = new ListTag(ListTag.class, pointList);
	
	tags.put("points", pointListTag);
	tags.put("minY", new IntTag(minY));
	tags.put("maxY", new IntTag(maxY));
}
 
Example #2
Source File: LocalBlockVector2DSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public <T> T[] toArray(T[] array) {
    int size = size();
    if (array == null || array.length < size) {
        array = (T[]) new BlockVector2D[size];
    }
    int index = 0;
    for (int i = 0; i < size; i++) {
        index = set.nextSetBit(index);
        int x = MathMan.unpairSearchCoordsX(index);
        int y = MathMan.unpairSearchCoordsY(index);
        array[i] = (T) new BlockVector2D(x, y);
        index++;
    }
    return array;
}
 
Example #3
Source File: Polygonal2DRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Polygonal2DRegion asRegion(Element container) {
	Element pointsElement = container.element("points");
	Element minYElement = container.element("minY");
	Element maxYElement = container.element("maxY");
	
	List<Element> pointElementList = pointsElement.elements("point");
	List<BlockVector2D> points = Lists.newArrayList();
	
	for (Element pointElement : pointElementList) {
		int x = Integer.parseInt(pointElement.elementText("x"));
		int z = Integer.parseInt(pointElement.elementText("z"));
		
		BlockVector2D point = new BlockVector2D(x, z);
		points.add(point);
	}
	
	int minY = Integer.parseInt(minYElement.getText());
	int maxY = Integer.parseInt(maxYElement.getText());
	
	return new Polygonal2DRegion((World)null, points, minY, maxY);
}
 
Example #4
Source File: Polygonal2DRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Element applyTo, Polygonal2DRegion region) {
	List<BlockVector2D> points = region.getPoints();
	int minY = region.getMinimumY();
	int maxY = region.getMaximumY();
	
	Element pointsElement = applyTo.addElement("points");
	for (BlockVector2D point : points) {
		Element pointElement = pointsElement.addElement("point");
		
		pointElement.addElement("x").addText(String.valueOf(point.getBlockX()));
		pointElement.addElement("z").addText(String.valueOf(point.getBlockZ()));
	}
	
	applyTo.addElement("minY").addText(String.valueOf(minY));
	applyTo.addElement("maxY").addText(String.valueOf(maxY));
}
 
Example #5
Source File: EllipsoidRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean selectSecondary(Vector position, SelectorLimits limits) {
    if (region.size() > 0) {
        final List<BlockVector2D> points = region.getPoints();

        final BlockVector2D lastPoint = points.get(region.size() - 1);
        if (lastPoint.getBlockX() == position.getBlockX() && lastPoint.getBlockZ() == position.getBlockZ()) {
            return false;
        }

        Optional<Integer> vertexLimit = limits.getPolygonVertexLimit();

        if (vertexLimit.isPresent() && points.size() > vertexLimit.get()) {
            return false;
        }
    }

    region.addPoint(position);
    region.expandY(position.getBlockY());

    return true;
}
 
Example #7
Source File: Polygonal2DRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Polygonal2DRegion asRegion(Map<String, Tag> tags) {
	ListTag pointsListTag = (ListTag) tags.get("points");
	List<Tag> pointList = pointsListTag.getValue();
	List<BlockVector2D> points = Lists.newArrayList();
	
	for (Tag vectorTag : pointList) {
		if (!(vectorTag instanceof ListTag)) {
			continue;
		}
		
		ListTag vectorListTag = (ListTag) vectorTag;
		int x = vectorListTag.getInt(0);
		int z = vectorListTag.getInt(1);
		
		BlockVector2D vector = new BlockVector2D(x, z);
		points.add(vector);
	}
	
	int minY = (int) tags.get("minY").getValue();
	int maxY = (int) tags.get("maxY").getValue();
	
	Polygonal2DRegion region = new Polygonal2DRegion();
	for (BlockVector2D point : points) {
		region.addPoint(point);
	}
	
	region.setMaximumY(maxY);
	region.setMinimumY(minY);
	return region;
}
 
Example #8
Source File: GriefPreventionFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void calculateRegions() {
    for (Claim claim : claims) {
        org.bukkit.Location bot = claim.getGreaterBoundaryCorner();
        if (world.equals(bot.getWorld())) {
            org.bukkit.Location top = claim.getGreaterBoundaryCorner();
            BlockVector2D pos1 = new BlockVector2D(bot.getBlockX(), bot.getBlockZ());
            BlockVector2D pos2 = new BlockVector2D(top.getBlockX(), top.getBlockZ());
            add(pos1, pos2);
        }
    }
}
 
Example #9
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<org.bukkit.util.Vector> getRegionPoints(ProtectedRegion region) {
	List<org.bukkit.util.Vector> result = new ArrayList<>();
	for (BlockVector2D point : region.getPoints()) {
		result.add(new org.bukkit.util.Vector(point.getX(), 0,point.getZ()));
	}
	return result;
}
 
Example #10
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<Vector> getRegionPoints(ProtectedRegion region) {
	List<Vector> result = new ArrayList<>();
	for (BlockVector2D point : region.getPoints()) {
		result.add(new Vector(point.getX(), 0,point.getZ()));
	}
	return result;
}
 
Example #11
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<org.bukkit.util.Vector> getRegionPoints(ProtectedRegion region) {
	List<org.bukkit.util.Vector> result = new ArrayList<>();
	for (BlockVector2D point : region.getPoints()) {
		result.add(new org.bukkit.util.Vector(point.getX(), 0,point.getZ()));
	}
	return result;
}
 
Example #12
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<org.bukkit.util.Vector> getRegionPoints(ProtectedRegion region) {
	List<org.bukkit.util.Vector> result = new ArrayList<>();
	for (BlockVector2D point : region.getPoints()) {
		result.add(new org.bukkit.util.Vector(point.getX(), 0,point.getZ()));
	}
	return result;
}
 
Example #13
Source File: ConvexPolyhedralRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector.
 *
 * @param oldSelector the old selector
 */
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector) {
    checkNotNull(oldSelector);

    if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
        final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;

        pos1 = convexPolyhedralRegionSelector.pos1;
        region = new ConvexPolyhedralRegion(convexPolyhedralRegionSelector.region);
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            region = new ConvexPolyhedralRegion(oldSelector.getIncompleteRegion().getWorld());
            return;
        }

        final int minY = oldRegion.getMinimumPoint().getBlockY();
        final int maxY = oldRegion.getMaximumPoint().getBlockY();

        region = new ConvexPolyhedralRegion(oldRegion.getWorld());

        for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(Integer.MAX_VALUE))) {
            region.addVertex(pt.toVector(minY));
            region.addVertex(pt.toVector(maxY));
        }

        learnChanges();
    }
}
 
Example #14
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void describeCUI(LocalSession session, Actor player) {
    final List<BlockVector2D> points = region.getPoints();
    for (int id = 0; id < points.size(); id++) {
        session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
    }

    session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
}
 
Example #15
Source File: PlotRegionFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void calculateRegions() {
    ArrayList<Plot> plots = new ArrayList<>(area.getPlots());
    for (Plot plot : plots) {
        Location pos1 = plot.getBottom();
        Location pos2 = plot.getTop();
        add(new BlockVector2D(pos1.getX(), pos1.getZ()), new BlockVector2D(pos2.getX(), pos2.getZ()));
    }
}
 
Example #16
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void learnChanges() {
    BlockVector2D pt = region.getPoints().get(0);
    pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
}
 
Example #17
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @deprecated cast {@code world} to {@link com.sk89q.worldedit.world.World}
 */
@Deprecated
public Polygonal2DRegionSelector(@Nullable LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
    this((World) world, points, minY, maxY);
}
 
Example #18
Source File: LocalWorldAdapter.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
    world.fixAfterFastMode(chunks);
}
 
Example #19
Source File: LocalWorldAdapter.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fixLighting(Iterable<BlockVector2D> chunks) {
    world.fixLighting(chunks);
}
 
Example #20
Source File: CylinderRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<BlockVector2D> polygonize(int maxPoints) {
    return Polygons.polygonizeCylinder(center, radius, maxPoints);
}
 
Example #21
Source File: SimpleWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
default void fixLighting(Iterable<BlockVector2D> chunks) {
}
 
Example #22
Source File: SimpleWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
default void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
}
 
Example #23
Source File: WorldWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fixLighting(Iterable<BlockVector2D> chunks) {
    parent.fixLighting(chunks);
}
 
Example #24
Source File: WorldWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
    parent.fixAfterFastMode(chunks);
}
 
Example #25
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create a new selector.
 *
 * @param world the world
 * @param points a list of points
 * @param minY the minimum Y
 * @param maxY the maximum Y
 */
public Polygonal2DRegionSelector(@Nullable World world, List<BlockVector2D> points, int minY, int maxY) {
    checkNotNull(points);
    
    final BlockVector2D pos2D = points.get(0);
    pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
    region = new Polygonal2DRegion(world, points, minY, maxY);
}
 
Example #26
Source File: CylinderRegion.java    From FastAsyncWorldedit with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the main center point of the region
 *
 * @param center the center point
 */
public void setCenter(Vector2D center) {
    this.center = new BlockVector2D(center);
}
 
Example #27
Source File: NukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {

}