(Breaking) Moved some packages around.

Most of the changes should not break *most* WorldEdit-using plugins,
but implementations of WorldEdit are broken by this change.
This commit is contained in:
sk89q
2014-04-02 19:08:50 -07:00
parent 6e70e8c862
commit 469cb8c8b3
185 changed files with 13303 additions and 13270 deletions

View File

@ -30,7 +30,7 @@ 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;
import com.sk89q.worldedit.world.storage.ChunkStore;
public abstract class AbstractRegion implements Region {
/**

View File

@ -32,10 +32,10 @@ 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.CUIRegion;
import com.sk89q.worldedit.cui.SelectionPointEvent;
import com.sk89q.worldedit.cui.SelectionPolygonEvent;
import com.sk89q.worldedit.cui.SelectionShapeEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionPolygonEvent;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.regions.polyhedron.Triangle;
public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.ChunkStore;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.util.HashSet;
import java.util.Iterator;

View File

@ -27,8 +27,8 @@ 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.CUIRegion;
import com.sk89q.worldedit.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
/**
* Selector for cuboids.

View File

@ -28,11 +28,11 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.cui.CUIRegion;
import com.sk89q.worldedit.cui.SelectionCylinderEvent;
import com.sk89q.worldedit.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.cui.SelectionPointEvent;
import com.sk89q.worldedit.cui.SelectionShapeEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionCylinderEvent;
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import java.text.NumberFormat;
/**

View File

@ -24,7 +24,7 @@ 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;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.util.Set;
import java.util.HashSet;

View File

@ -27,9 +27,9 @@ 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.CUIRegion;
import com.sk89q.worldedit.cui.SelectionEllipsoidPointEvent;
import com.sk89q.worldedit.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
/**
* Selector for ellipsoids.

View File

@ -28,10 +28,10 @@ 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.CUIRegion;
import com.sk89q.worldedit.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.cui.SelectionPoint2DEvent;
import com.sk89q.worldedit.cui.SelectionShapeEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
/**
* Selector for polygonal regions.

View File

@ -0,0 +1,189 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.regions.Region;
/**
* Generates solid and hollow shapes according to materials returned by the
* {@link #getBiome} method.
*
* @author TomyLobo
*/
public abstract class ArbitraryBiomeShape {
private final FlatRegion extent;
private int cacheOffsetX;
private int cacheOffsetZ;
@SuppressWarnings("FieldCanBeLocal")
private int cacheSizeX;
private int cacheSizeZ;
public ArbitraryBiomeShape(Region extent) {
if (extent instanceof FlatRegion) {
this.extent = (FlatRegion) extent;
}
else {
// TODO: polygonize
this.extent = new CuboidRegion(extent.getWorld(), extent.getMinimumPoint(), extent.getMaximumPoint());
}
Vector2D min = extent.getMinimumPoint().toVector2D();
Vector2D max = extent.getMaximumPoint().toVector2D();
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = (int) (max.getX() - cacheOffsetX + 2);
cacheSizeZ = (int) (max.getZ() - cacheOffsetZ + 2);
cache = new BiomeType[cacheSizeX * cacheSizeZ];
}
protected Iterable<Vector2D> getExtent() {
return extent.asFlatRegion();
}
/**
* Cache entries:
* null = unknown
* OUTSIDE = outside
* else = inside
*/
private final BiomeType[] cache;
/**
* Override this function to specify the shape to generate.
*
* @param x X coordinate to be queried
* @param z Z coordinate to be queried
* @param defaultBiomeType The default biome for the current column.
* @return material to place or null to not place anything.
*/
protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBiomeType);
private BiomeType getBiomeCached(int x, int z, BiomeType biomeType) {
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
final BiomeType cacheEntry = cache[index];
if (cacheEntry == null) {// unknown, fetch material
final BiomeType material = getBiome(x, z, biomeType);
if (material == null) {
// outside
cache[index] = OUTSIDE;
return null;
}
cache[index] = material;
return material;
}
if (cacheEntry == OUTSIDE) {
// outside
return null;
}
return cacheEntry;
}
private boolean isInsideCached(int x, int z, BiomeType biomeType) {
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
final BiomeType cacheEntry = cache[index];
if (cacheEntry == null) {
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
return getBiomeCached(x, z, biomeType) != null;
}
return cacheEntry != OUTSIDE;
}
/**
* Generates the shape.
*
* @param editSession The EditSession to use.
* @param biomeType The default biome type.
* @param hollow Specifies whether to generate a hollow shape.
* @return number of affected blocks.
*/
public int generate(EditSession editSession, BiomeType biomeType, boolean hollow) {
int affected = 0;
for (Vector2D position : getExtent()) {
int x = position.getBlockX();
int z = position.getBlockZ();
if (!hollow) {
final BiomeType material = getBiome(x, z, biomeType);
if (material != OUTSIDE) {
editSession.getWorld().setBiome(position, material);
++affected;
}
continue;
}
final BiomeType material = getBiomeCached(x, z, biomeType);
if (material == null) {
continue;
}
boolean draw = false;
do {
if (!isInsideCached(x + 1, z, biomeType)) {
draw = true;
break;
}
if (!isInsideCached(x - 1, z, biomeType)) {
draw = true;
break;
}
if (!isInsideCached(x, z + 1, biomeType)) {
draw = true;
break;
}
if (!isInsideCached(x, z - 1, biomeType)) {
draw = true;
break;
}
} while (false);
if (!draw) {
continue;
}
editSession.getWorld().setBiome(position, material);
++affected;
}
return affected;
}
private static final BiomeType OUTSIDE = new BiomeType() {
public String getName() {
throw new UnsupportedOperationException();
}
};
}

View File

@ -0,0 +1,211 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.Region;
/**
* Generates solid and hollow shapes according to materials returned by the
* {@link #getMaterial} method.
*
* @author TomyLobo
*/
public abstract class ArbitraryShape {
protected final Region extent;
private int cacheOffsetX;
private int cacheOffsetY;
private int cacheOffsetZ;
@SuppressWarnings("FieldCanBeLocal")
private int cacheSizeX;
private int cacheSizeY;
private int cacheSizeZ;
public ArbitraryShape(Region extent) {
this.extent = extent;
Vector min = extent.getMinimumPoint();
Vector max = extent.getMaximumPoint();
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetY = min.getBlockY() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = (int) (max.getX() - cacheOffsetX + 2);
cacheSizeY = (int) (max.getY() - cacheOffsetY + 2);
cacheSizeZ = (int) (max.getZ() - cacheOffsetZ + 2);
cache = new short[cacheSizeX * cacheSizeY * cacheSizeZ];
}
protected Region getExtent() {
return extent;
}
/**
* Cache entries:
* 0 = unknown
* -1 = outside
* -2 = inside but type and data 0
* > 0 = inside, value = (type | (data << 8)), not handling data < 0
*/
private final short[] cache;
/**
* Override this function to specify the shape to generate.
*
* @param x X coordinate to be queried
* @param y Y coordinate to be queried
* @param z Z coordinate to be queried
* @param defaultMaterial The material returned by the pattern for the current block.
* @return material to place or null to not place anything.
*/
protected abstract BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial);
private BaseBlock getMaterialCached(int x, int y, int z, Pattern pattern) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
final short cacheEntry = cache[index];
switch (cacheEntry) {
case 0:
// unknown, fetch material
final BaseBlock material = getMaterial(x, y, z, pattern.next(new BlockVector(x, y, z)));
if (material == null) {
// outside
cache[index] = -1;
return null;
}
short newCacheEntry = (short) (material.getType() | ((material.getData() + 1) << 8));
if (newCacheEntry == 0) {
// type and data 0
newCacheEntry = -2;
}
cache[index] = newCacheEntry;
return material;
case -1:
// outside
return null;
case -2:
// type and data 0
return new BaseBlock(0, 0);
}
return new BaseBlock(cacheEntry & 255, ((cacheEntry >> 8) - 1) & 15);
}
private boolean isInsideCached(int x, int y, int z, Pattern pattern) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
switch (cache[index]) {
case 0:
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
return getMaterialCached(x, y, z, pattern) != null;
case -1:
// outside
return false;
default:
// inside
return true;
}
}
/**
* Generates the shape.
*
* @param editSession The EditSession to use.
* @param pattern The pattern to generate default materials from.
* @param hollow Specifies whether to generate a hollow shape.
* @return number of affected blocks.
* @throws MaxChangedBlocksException
*/
public int generate(EditSession editSession, Pattern pattern, boolean hollow) throws MaxChangedBlocksException {
int affected = 0;
for (BlockVector position : getExtent()) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
if (!hollow) {
final BaseBlock material = getMaterial(x, y, z, pattern.next(position));
if (material != null && editSession.setBlock(position, material)) {
++affected;
}
continue;
}
final BaseBlock material = getMaterialCached(x, y, z, pattern);
if (material == null) {
continue;
}
boolean draw = false;
do {
if (!isInsideCached(x + 1, y, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x - 1, y, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y, z + 1, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y, z - 1, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y + 1, z, pattern)) {
draw = true;
break;
}
if (!isInsideCached(x, y - 1, z, pattern)) {
draw = true;
break;
}
} while (false);
if (!draw) {
continue;
}
if (editSession.setBlock(position, material)) {
++affected;
}
}
return affected;
}
}

View File

@ -0,0 +1,26 @@
package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.regions.Region;
/**
* Generates solid and hollow shapes according to materials returned by the
* {@link #getMaterial} method.
*
* @author TomyLobo
*/
public class RegionShape extends ArbitraryShape {
public RegionShape(Region extent) {
super(extent);
}
@Override
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
if (!this.extent.contains(new Vector(x, y, z))) {
return null;
}
return defaultMaterial;
}
}

View File

@ -0,0 +1,62 @@
package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
private final Vector unit;
private final Vector zero2;
private Vector current = new Vector();
private EditSession editSession;
public WorldEditExpressionEnvironment(EditSession editSession, Vector unit, Vector zero) {
this.editSession = editSession;
this.unit = unit;
this.zero2 = zero.add(0.5, 0.5, 0.5);
}
public BlockVector toWorld(double x, double y, double z) {
// unscale, unoffset, round-nearest
return new Vector(x, y, z).multiply(unit).add(zero2).toBlockPoint();
}
public Vector toWorldRel(double x, double y, double z) {
return current.add(x, y, z);
}
@Override
public int getBlockType(double x, double y, double z) {
return editSession.getBlockType(toWorld(x, y, z));
}
@Override
public int getBlockData(double x, double y, double z) {
return editSession.getBlockData(toWorld(x, y, z));
}
@Override
public int getBlockTypeAbs(double x, double y, double z) {
return editSession.getBlockType(new Vector(x, y, z));
}
@Override
public int getBlockDataAbs(double x, double y, double z) {
return editSession.getBlockData(new Vector(x, y, z));
}
@Override
public int getBlockTypeRel(double x, double y, double z) {
return editSession.getBlockType(toWorldRel(x, y, z));
}
@Override
public int getBlockDataRel(double x, double y, double z) {
return editSession.getBlockData(toWorldRel(x, y, z));
}
public void setCurrentBlock(Vector current) {
this.current = current;
}
}