Added support for non-128 worldheights
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.data.ChunkStore;
|
||||
@@ -40,6 +41,10 @@ public class CuboidRegion implements Region {
|
||||
* Store the second point.
|
||||
*/
|
||||
private Vector pos2;
|
||||
/**
|
||||
* Stores the world.
|
||||
*/
|
||||
private LocalWorld world;
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid region.
|
||||
@@ -48,7 +53,19 @@ public class CuboidRegion implements Region {
|
||||
* @param pos2
|
||||
*/
|
||||
public CuboidRegion(Vector pos1, Vector pos2) {
|
||||
this(null, pos1, pos2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid region.
|
||||
*
|
||||
* @param world
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
*/
|
||||
public CuboidRegion(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this.pos1 = pos1;
|
||||
this.world = world;
|
||||
this.pos2 = pos2;
|
||||
}
|
||||
|
||||
@@ -172,8 +189,8 @@ public class CuboidRegion implements Region {
|
||||
}
|
||||
}
|
||||
|
||||
pos1 = pos1.clampY(0, 127);
|
||||
pos2 = pos2.clampY(0, 127);
|
||||
pos1 = pos1.clampY(0, world.getMaxY());
|
||||
pos2 = pos2.clampY(0, world.getMaxY());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,8 +241,8 @@ public class CuboidRegion implements Region {
|
||||
}
|
||||
}
|
||||
|
||||
pos1 = pos1.clampY(0, 127);
|
||||
pos2 = pos2.clampY(0, 127);
|
||||
pos1 = pos1.clampY(0, world == null ? 127 : world.getMaxY());
|
||||
pos2 = pos2.clampY(0, world == null ? 127 : world.getMaxY());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,4 +370,12 @@ public class CuboidRegion implements Region {
|
||||
public String toString() {
|
||||
return getMinimumPoint() + " - " + getMaximumPoint();
|
||||
}
|
||||
|
||||
public LocalWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(LocalWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
@@ -37,12 +38,18 @@ import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
protected BlockVector pos1;
|
||||
protected BlockVector pos2;
|
||||
protected CuboidRegion region = new CuboidRegion(new Vector(), new Vector());
|
||||
protected CuboidRegion region;
|
||||
|
||||
public CuboidRegionSelector(LocalWorld world) {
|
||||
region = new CuboidRegion(world, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
public CuboidRegionSelector() {
|
||||
this((LocalWorld)null);
|
||||
}
|
||||
|
||||
public CuboidRegionSelector(RegionSelector oldSelector) {
|
||||
region = new CuboidRegion(oldSelector.getIncompleteRegion().getWorld(), new Vector(), new Vector());
|
||||
if (oldSelector instanceof CuboidRegionSelector) {
|
||||
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.data.ChunkStore;
|
||||
@@ -43,30 +44,43 @@ public class Polygonal2DRegion implements Region {
|
||||
protected int minY;
|
||||
protected int maxY;
|
||||
protected boolean hasY = false;
|
||||
protected LocalWorld world;
|
||||
|
||||
/**
|
||||
* Construct the region.
|
||||
* Construct the region
|
||||
*/
|
||||
public Polygonal2DRegion() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the region.
|
||||
*
|
||||
* @param world
|
||||
*/
|
||||
public Polygonal2DRegion(LocalWorld world) {
|
||||
points = new ArrayList<BlockVector2D>();
|
||||
minY = 0;
|
||||
maxY = 0;
|
||||
hasY = false;
|
||||
this.world = world;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the region.
|
||||
*
|
||||
* @param world
|
||||
* @param points
|
||||
* @param minY
|
||||
* @param maxY
|
||||
*/
|
||||
public Polygonal2DRegion(List<BlockVector2D> points, int minY, int maxY) {
|
||||
public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
|
||||
this.points = points;
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
hasY = true;
|
||||
this.world = world;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
@@ -109,6 +123,9 @@ public class Polygonal2DRegion implements Region {
|
||||
minY = Math.min(oldMinY, oldMaxY);
|
||||
maxY = Math.max(oldMinY, oldMaxY);
|
||||
|
||||
minY = Math.min(Math.max(0, minY), world == null ? 127 : world.getMaxY());
|
||||
maxY = Math.min(Math.max(0, maxY), world == null ? 127 : world.getMaxY());
|
||||
|
||||
min = new BlockVector(minX, minY, minZ);
|
||||
max = new BlockVector(maxX, maxY, maxZ);
|
||||
}
|
||||
@@ -567,4 +584,12 @@ public class Polygonal2DRegion implements Region {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
}
|
||||
|
||||
public LocalWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(LocalWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionMinMaxEvent;
|
||||
@@ -39,7 +40,11 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||
*/
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
protected BlockVector pos1;
|
||||
protected Polygonal2DRegion region = new Polygonal2DRegion();
|
||||
protected Polygonal2DRegion region;
|
||||
|
||||
public Polygonal2DRegionSelector(LocalWorld world) {
|
||||
region = new Polygonal2DRegion(world);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos.equals(pos1)) {
|
||||
@@ -47,7 +52,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
}
|
||||
|
||||
pos1 = pos.toBlockVector();
|
||||
region = new Polygonal2DRegion();
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
|
||||
@@ -124,7 +129,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
region = new Polygonal2DRegion();
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import java.util.Set;
|
||||
@@ -101,4 +102,18 @@ public interface Region extends Iterable<BlockVector> {
|
||||
* @return
|
||||
*/
|
||||
public Set<Vector2D> getChunks();
|
||||
|
||||
/**
|
||||
* Get the world the selection is in
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LocalWorld getWorld();
|
||||
|
||||
/**
|
||||
* Sets the world the selection is in
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void setWorld(LocalWorld world);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user