Upstream merge of the region package and things that may have broken with it.

This commit is contained in:
MattBDev 2020-08-18 15:48:31 -04:00
parent de34047365
commit 79b5612311
48 changed files with 852 additions and 678 deletions

View File

@ -3,24 +3,22 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
@ -51,11 +49,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import io.papermc.lib.PaperLib;
import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.*;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.TreeType;
@ -69,15 +62,42 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.slf4j.Logger;
import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public class BukkitWorld extends AbstractWorld {
private static final Logger logger = WorldEdit.logger;
private static final boolean HAS_3D_BIOMES;
private static final Map<Integer, Effect> effects = new HashMap<>();
static {
for (Effect effect : Effect.values()) {
effects.put(effect.getId(), effect);
@SuppressWarnings("deprecation")
int id = effect.getId();
effects.put(id, effect);
}
boolean temp;
try {
World.class.getMethod("getBiome", int.class, int.class, int.class);
temp = true;
} catch (NoSuchMethodException e) {
temp = false;
}
HAS_3D_BIOMES = temp;
}
private WeakReference<World> worldRef;
@ -157,7 +177,9 @@ public class BukkitWorld extends AbstractWorld {
World tmp = worldRef.get();
if (tmp == null) {
tmp = Bukkit.getWorld(worldNameRef);
if (tmp != null) worldRef = new WeakReference<>(tmp);
if (tmp != null) {
worldRef = new WeakReference<>(tmp);
}
}
return checkNotNull(tmp, "The world was unloaded and the reference is unavailable");
}
@ -187,7 +209,16 @@ public class BukkitWorld extends AbstractWorld {
@Override
public Path getStoragePath() {
return getWorld().getWorldFolder().toPath();
Path worldFolder = getWorld().getWorldFolder().toPath();
switch (getWorld().getEnvironment()) {
case NETHER:
return worldFolder.resolve("DIM-1");
case THE_END:
return worldFolder.resolve("DIM1");
case NORMAL:
default:
return worldFolder;
}
}
@Override
@ -299,7 +330,7 @@ public class BukkitWorld extends AbstractWorld {
}
/**
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes.
*/
private static final EnumMap<TreeGenerator.TreeType, TreeType> treeTypeMapping =
new EnumMap<>(TreeGenerator.TreeType.class);
@ -385,6 +416,7 @@ public class BukkitWorld extends AbstractWorld {
return getWorld().getMaxHeight() - 1;
}
@SuppressWarnings("deprecation")
@Override
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
World world = getWorld();
@ -488,8 +520,8 @@ public class BukkitWorld extends AbstractWorld {
return worldNativeAccess.setBlock(position, block, sideEffects);
} catch (Exception e) {
if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) {
logger.warn("Tried to set a corrupt tile entity at " + position.toString() +
": " + ((BaseBlock) block).getNbtData(), e);
logger.warn("Tried to set a corrupt tile entity at " + position.toString()
+ ": " + ((BaseBlock) block).getNbtData(), e);
} else {
logger.warn("Failed to set block via adapter, falling back to generic", e);
}
@ -535,20 +567,29 @@ public class BukkitWorld extends AbstractWorld {
}
@Override
public BiomeType getBiome(BlockVector2 position) {
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockZ()));
public BiomeType getBiome(BlockVector3 position) {
if (HAS_3D_BIOMES) {
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
} else {
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockZ()));
}
}
@SuppressWarnings("deprecation")
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
getWorld().setBiome(position.getBlockX(), position.getBlockZ(), BukkitAdapter.adapt(biome));
public boolean setBiome(BlockVector3 position, BiomeType biome) {
if (HAS_3D_BIOMES) {
getWorld().setBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ(), BukkitAdapter.adapt(biome));
} else {
getWorld().setBiome(position.getBlockX(), position.getBlockZ(), BukkitAdapter.adapt(biome));
}
return true;
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException {
return setBlock(BlockVector3.at(x,y,z), block);
return setBlock(BlockVector3.at(x, y, z), block);
}
@Override
@ -558,12 +599,12 @@ public class BukkitWorld extends AbstractWorld {
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return setBiome(BlockVector2.at(x,z), biome);
return setBiome(BlockVector2.at(x, z), biome);
}
@Override
public void refreshChunk(int X, int Z) {
getWorld().refreshChunk(X, Z);
public void refreshChunk(int chunkX, int chunkZ) {
getWorld().refreshChunk(chunkX, chunkZ);
}
@Override

View File

@ -38,7 +38,9 @@ public interface VirtualWorld extends SimpleWorld, Closeable {
void close(boolean update) throws IOException;
default void handleBlockInteract(Player player, BlockVector3 pos, BlockInteractEvent event) {}
default void handleBlockInteract(Player player, BlockVector3 pos, BlockInteractEvent event) {
}
default void handlePlayerInput(Player player, PlayerInputEvent event) {}
default void handlePlayerInput(Player player, PlayerInputEvent event) {
}
}

View File

@ -230,7 +230,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
private ImageViewer viewer;
// Used for visualizing the world by sending chunk packets
// These three variables should be set together
// private IQueueExtent packetQueue;
// private IQueueExtent packetQueue;
private Player player;
private BlockVector2 chunkOffset = BlockVector2.ZERO;
private EditSession editSession;
@ -895,6 +895,11 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
return getFolder().toPath();
}
@Override
public int getMinY() {
return 0;
}
@Override
public boolean regenerateChunk(int x, int z, @Nullable BiomeType biome, @Nullable Long seed) {
// Unsupported

View File

@ -292,7 +292,7 @@ public class WorldWrapper extends AbstractWorld {
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return parent.setBiome(x, y , z, biome);
return parent.setBiome(x, y, z, biome);
}
@Override

View File

@ -223,7 +223,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
@Nullable BlockBag blockBag, @Nullable EditSessionEvent event) {
this(new EditSessionBuilder(world).player(player).limit(limit).changeSet(changeSet).allowedRegions(allowedRegions).autoQueue(autoQueue).fastmode(fastmode).checkMemory(checkMemory).combineStages(combineStages).blockBag(blockBag).eventBus(bus).event(event));
}
/**
* Construct the object with a maximum number of blocks and a block bag.
*
@ -2925,7 +2925,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
final int[] timedOut = {0};
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
@Override
protected BiomeType getBiome(int x, int z, BiomeType defaultBiomeType) {
protected BiomeType getBiome(int x, int y, int z, BiomeType defaultBiomeType) {
environment.setCurrentBlock(x, 0, z);
double scaledX = (x - zero2D.getX()) / unit2D.getX();
double scaledZ = (z - zero2D.getZ()) / unit2D.getZ();

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extent;
@ -22,6 +22,8 @@ package com.sk89q.worldedit.extent;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector2;
@ -72,18 +74,51 @@ public interface OutputExtent {
* @param position the (x, z) location to set the biome at
* @param biome the biome to set to
* @return true if the biome was successfully set (return value may not be accurate)
* @deprecated Biomes in Minecraft are 3D now, use {@link OutputExtent#setBiome(BlockVector3, BiomeType)}
*/
@Deprecated
default boolean setBiome(BlockVector2 position, BiomeType biome) {
return setBiome(position.getX(), 0, position.getBlockZ(), biome);
}
@NonAbstractForCompatibility(
delegateName = "setBiome",
delegateParams = { int.class, int.class, int.class, BiomeType.class }
)
// The defaults need to remain for compatibility (the actual implementation still needs to override one of these)
default boolean setBiome(int x, int y, int z, BiomeType biome) {
DeprecationUtil.checkDelegatingOverride(getClass());
return setBiome(MutableBlockVector2.get(x, z), biome);
}
/**
* Set the light value
* Set the biome.
*
* <p>
* As implementation varies per Minecraft version, this may set more than
* this position's biome. On versions prior to 1.15, this will set the entire
* column. On later versions it will set the 4x4x4 cube.
* </p>
*
* @param position the (x, y, z) location to set the biome at
* @param biome the biome to set to
* @return true if the biome was successfully set (return value may not be accurate)
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "setBiome",
delegateParams = { BlockVector3.class, BiomeType.class }
)
default boolean setBiome(BlockVector3 position, BiomeType biome) {
DeprecationUtil.checkDelegatingOverride(getClass());
return setBiome(position.toBlockVector2(), biome);
}
/**
* Set the light value.
*
* @param position position of the block
* @param value light level to set
@ -92,10 +127,11 @@ public interface OutputExtent {
setBlockLight(position.getX(), position.getY(), position.getZ(), value);
}
default void setBlockLight(int x, int y, int z, int value) {}
default void setBlockLight(int x, int y, int z, int value) {
}
/**
* Set the sky light value
* Set the sky light value.
*
* @param position position of the block
* @param value light level to set
@ -104,7 +140,8 @@ public interface OutputExtent {
setSkyLight(position.getX(), position.getY(), position.getZ(), value);
}
default void setSkyLight(int x, int y, int z, int value) {}
default void setSkyLight(int x, int y, int z, int value) {
}
/**
* Return an {@link Operation} that should be called to tie up loose ends

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -208,6 +208,16 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
return chunks;
}
// Sub-class utilities
protected final int getWorldMinY() {
return world == null ? 0 : world.getMinY();
}
protected final int getWorldMaxY() {
return world == null ? 255 : world.getMaxY();
}
@Override
public int hashCode() {
int worldHash = this.world == null ? 7 : this.world.hashCode();

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -68,7 +68,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
private BlockVector3 centerAccum = BlockVector3.ZERO;
/**
* The last triangle that caused a {@link #contains(BlockVector3)} to classify a point as "outside". Used for optimization.
* The last triangle that caused a {@link #contains(BlockVector3)}} to classify a point as "outside". Used for optimization.
*/
private Triangle lastTriangle;
@ -127,12 +127,14 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
return false;
}
Vector3 vertexD = vertex.toVector3();
if (vertices.size() == 3) {
if (vertexBacklog.contains(vertex)) {
return false;
}
if (containsRaw(vertex.toVector3())) {
if (containsRaw(vertexD)) {
return vertexBacklog.add(vertex);
}
}
@ -150,19 +152,22 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
switch (vertices.size()) {
case 0:
case 1:
case 2:
// Incomplete, can't make a mesh yet
return true;
case 0:
case 1:
case 2:
// Incomplete, can't make a mesh yet
return true;
case 3:
// Generate minimal mesh to start from
final BlockVector3[] v = vertices.toArray(new BlockVector3[vertices.size()]);
case 3:
// Generate minimal mesh to start from
final BlockVector3[] v = vertices.toArray(new BlockVector3[0]);
triangles.add((new Triangle(v[0].toVector3(), v[1].toVector3(), v[2].toVector3())));
triangles.add((new Triangle(v[0].toVector3(), v[2].toVector3(), v[1].toVector3())));
return true;
triangles.add((new Triangle(v[0].toVector3(), v[1].toVector3(), v[2].toVector3())));
triangles.add((new Triangle(v[0].toVector3(), v[2].toVector3(), v[1].toVector3())));
return true;
default:
break;
}
// Look for triangles that face the vertex and remove them
@ -171,7 +176,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
final Triangle triangle = it.next();
// If the triangle can't be seen, it's not relevant
if (!triangle.above(vertex.toVector3())) {
if (!triangle.above(vertexD)) {
continue;
}
@ -191,7 +196,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
// Add triangles between the remembered edges and the new vertex.
for (Edge edge : borderEdges) {
triangles.add(edge.createTriangle(vertex.toVector3()));
triangles.add(edge.createTriangle(vertexD));
}
if (!vertexBacklog.isEmpty()) {
@ -275,19 +280,12 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
return false;
}
final int x = position.getBlockX();
final int y = position.getBlockY();
final int z = position.getBlockZ();
final BlockVector3 min = getMinimumPoint();
final BlockVector3 max = getMaximumPoint();
if (x < min.getBlockX()) return false;
if (x > max.getBlockX()) return false;
if (y < min.getBlockY()) return false;
if (y > max.getBlockY()) return false;
if (z < min.getBlockZ()) return false;
if (z > max.getBlockZ()) return false;
if (!position.containedWithin(min, max)) {
return false;
}
return containsRaw(position.toVector3());
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -49,7 +49,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class CuboidRegion extends AbstractRegion implements FlatRegion {
private int minX, minY, minZ, maxX, maxY, maxZ;
private int minX;
private int minY;
private int minZ;
private int maxX;
private int maxY;
private int maxZ;
private BlockVector3 pos1;
private BlockVector3 pos2;
@ -318,16 +323,17 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
final int size = (maxX - minX + 1) * (maxZ - minZ + 1);
return new AbstractSet<BlockVector2>() {
@NotNull @Override
@NotNull
@Override
public Iterator<BlockVector2> iterator() {
return new Iterator<BlockVector2>() {
final MutableBlockVector2 mutable = new MutableBlockVector2(0, 0);
int bx = minX;
int bz = minZ;
final int bx = minX;
final int bz = minZ;
int tx = maxX;
int tz = maxZ;
final int tx = maxX;
final int tz = maxZ;
private int x = minX;
private int z = minZ;
@ -444,16 +450,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
return new Iterator<BlockVector3>() {
final MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();
private final BlockVector3 min = getMinimumPoint();
private final BlockVector3 max = getMaximumPoint();
int bx = min.getBlockX();
int by = min.getBlockY();
int bz = min.getBlockZ();
final int bx = min.getBlockX();
final int by = min.getBlockY();
final int bz = min.getBlockZ();
int tx = max.getBlockX();
int ty = max.getBlockY();
int tz = max.getBlockZ();
final int tx = max.getBlockX();
final int ty = max.getBlockY();
final int tz = max.getBlockZ();
private int x = min.getBlockX();
private int y = min.getBlockY();
@ -524,8 +530,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
public Iterator<BlockVector3> iterator_old() {
final MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
return new Iterator<BlockVector3>() {
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();
private final BlockVector3 min = getMinimumPoint();
private final BlockVector3 max = getMaximumPoint();
private int nextX = min.getBlockX();
private int nextY = min.getBlockY();
private int nextZ = min.getBlockZ();
@ -546,7 +552,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
if (++nextZ > max.getBlockZ()) {
nextZ = min.getBlockZ();
if (++nextY > max.getBlockY()) {
if (!hasNext()) throw new NoSuchElementException();
if (!hasNext()) {
throw new NoSuchElementException();
}
nextX = max.getBlockX();
nextZ = max.getBlockZ();
nextY = max.getBlockY();
@ -562,8 +570,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public Iterable<BlockVector2> asFlatRegion() {
return () -> new Iterator<BlockVector2>() {
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();
private final BlockVector3 min = getMinimumPoint();
private final BlockVector3 max = getMaximumPoint();
private int nextX = min.getBlockX();
private int nextZ = min.getBlockZ();
@ -574,7 +582,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector2 next() {
if (!hasNext()) throw new NoSuchElementException();
if (!hasNext()) {
throw new NoSuchElementException();
}
BlockVector2 answer = BlockVector2.at(nextX, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
@ -717,13 +727,13 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
boolean trimX = lowerX != 0 || upperX != 15;
boolean trimZ = lowerZ != 0 || upperZ != 15;
int indexY, index;
for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) {
if (set.hasSection(layer)) {
char[] arr = set.load(layer);
if (trimX || trimZ) {
indexY = 0;
int indexY = 0;
for (int y = 0; y < 16; y++, indexY += 256) {
int index;
if (trimZ) {
index = indexY;
for (int z = 0; z < lowerZ; z++) {

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.geom.Polygons;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.math.BigDecimal;
@ -54,7 +55,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
private boolean hasY = false;
/**
* Construct the region
* Construct the region.
*/
public CylinderRegion() {
this((World) null);
@ -116,7 +117,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
/**
* Sets the main center point of the region
* Sets the main center point of the region.
*
* @param center the center point
*/
@ -125,7 +126,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
/**
* Returns the radius of the cylinder
* Returns the radius of the cylinder.
*
* @return the radius along the X and Z axes
*/
@ -134,7 +135,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
/**
* Sets the radius of the cylinder
* Sets the radius of the cylinder.
*
* @param radius the radius along the X and Z axes
*/
@ -144,7 +145,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
/**
* Extends the radius to be at least the given radius
* Extends the radius to be at least the given radius.
*
* @param minRadius the minimum radius
*/
@ -233,7 +234,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
throw new RegionOperationException("Cylinders changes must be even for each horizontal dimensions.");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.cylinder.error.even-horizontal"));
}
return diff.divide(2).floor();
@ -253,7 +254,6 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* Expand the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
*/
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
@ -375,7 +375,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
/**
* Returns string representation in the format
* Returns string representation in the format.
* "(centerX, centerZ) - (radiusX, radiusZ) - (minY, maxY)"
*
* @return string

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -29,6 +29,7 @@ import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
@ -125,8 +126,7 @@ public class EllipsoidRegion extends AbstractRegion {
BlockVector3 diff = BlockVector3.ZERO.add(changes);
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
throw new RegionOperationException(
"Ellipsoid changes must be even for each dimensions.");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.ellipsoid.error.even-horizontal"));
}
return diff.divide(2).floor();
@ -214,8 +214,10 @@ public class EllipsoidRegion extends AbstractRegion {
continue;
}
chunks.add(
BlockVector2.at(x >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
chunks.add(BlockVector2.at(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));
}
}
@ -347,10 +349,9 @@ public class EllipsoidRegion extends AbstractRegion {
if (remainderZ < 0) {
continue;
}
int diffX, minX, maxX;
diffX = (int) Math.floor(Math.sqrt(remainderZ));
minX = Math.max(0, cx - diffX - bx);
maxX = Math.min(15, cx + diffX - bx);
int diffX = (int) Math.floor(Math.sqrt(remainderZ));
int minX = Math.max(0, cx - diffX - bx);
int maxX = Math.min(15, cx + diffX - bx);
block.filter(filter, minX, y, z, maxX, y, z);
}
}
@ -371,17 +372,15 @@ public class EllipsoidRegion extends AbstractRegion {
int cx1 = Math.abs(bx - cx);
int cx2 = Math.abs(tx - cx);
int cxMax, cxMin;
cxMin = Math.min(cx1, cx2);
cxMax = Math.max(cx1, cx2);
int cxMin = Math.min(cx1, cx2);
int cxMax = Math.max(cx1, cx2);
int cxMin2 = cxMin * cxMin;
int cxMax2 = cxMax * cxMax;
int cz1 = Math.abs(bz - cz);
int cz2 = Math.abs(tz - cz);
int czMax, czMin;
czMin = Math.min(cz1, cz2);
czMax = Math.max(cz1, cz2);
int czMin = Math.min(cz1, cz2);
int czMax = Math.max(cz1, cz2);
int czMin2 = czMin * czMin;
int czMax2 = czMax * czMax;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -24,14 +24,14 @@ import com.sk89q.worldedit.math.BlockVector2;
public interface FlatRegion extends Region {
/**
* Gets the minimum Y value
* Gets the minimum Y value.
*
* @return the Y value
*/
int getMinimumY();
/**
* Gets the maximum Y value
* Gets the maximum Y value.
*
* @return the Y value
*/

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -22,6 +22,7 @@ package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.util.Collections;
@ -74,17 +75,17 @@ public class NullRegion implements Region {
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable"));
}
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable"));
}
@Override
public void shift(BlockVector3 change) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable"));
}
@Override

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -23,6 +23,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.math.BigDecimal;
@ -45,7 +46,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
private boolean hasY = false;
/**
* Construct the region
* Construct the region.
*/
public Polygonal2DRegion() {
this((World) null);
@ -118,10 +119,18 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
for (BlockVector2 v : points) {
int x = v.getBlockX();
int z = v.getBlockZ();
if (x < minX) minX = x;
if (z < minZ) minZ = z;
if (x > maxX) maxX = x;
if (z > maxZ) maxZ = z;
if (x < minX) {
minX = x;
}
if (z < minZ) {
minZ = z;
}
if (x > maxX) {
maxX = x;
}
if (z > maxZ) {
maxZ = z;
}
}
int oldMinY = minY;
@ -129,8 +138,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
minY = Math.min(oldMinY, oldMaxY);
maxY = Math.max(oldMinY, oldMaxY);
minY = Math.min(Math.max(0, minY), world == null ? 255 : world.getMaxY());
maxY = Math.min(Math.max(0, maxY), world == null ? 255 : world.getMaxY());
minY = Math.min(Math.max(getWorldMinY(), minY), getWorldMaxY());
maxY = Math.min(Math.max(getWorldMinY(), maxY), getWorldMaxY());
min = BlockVector2.at(minX, minZ);
max = BlockVector2.at(maxX, maxZ);
@ -201,7 +210,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
@Override
public long getVolume() {
long area = 0;
int i, j = points.size() - 1;
int i;
int j = points.size() - 1;
for (i = 0; i < points.size(); ++i) {
long x = points.get(j).getBlockX() + points.get(i).getBlockX();
@ -236,7 +246,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
public void expand(BlockVector3... changes) throws RegionOperationException {
for (BlockVector3 change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be expanded vertically.");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.polygon2d.error.expand-only-vertical"));
}
int changeY = change.getBlockY();
if (changeY > 0) {
@ -252,7 +262,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
public void contract(BlockVector3... changes) throws RegionOperationException {
for (BlockVector3 change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be contracted vertically.");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.polygon2d.error.contract-only-vertical"));
}
int changeY = change.getBlockY();
if (changeY > 0) {
@ -285,10 +295,14 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
public boolean contains(int targetX, int targetZ) {
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
int xNew;
int zNew;
int xOld;
int zOld;
int x1;
int z1;
int x2;
int z2;
long crossproduct;
int i;
@ -317,7 +331,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
- ((long) z2 - (long) z1) * (long) (targetX - x1);
if (crossproduct == 0) {
if ((z1 <= targetZ) == (targetZ <= z2)) return true; //on edge
if ((z1 <= targetZ) == (targetZ <= z2)) {
return true; //on edge
}
} else if (crossproduct < 0 && (x1 != targetX)) {
inside = !inside;
}
@ -357,15 +373,17 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
int xNew;
int zNew;
int x1;
int z1;
int x2;
int z2;
long crossproduct;
int i;
xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ();
int xOld = points.get(npoints - 1).getBlockX();
int zOld = points.get(npoints - 1).getBlockZ();
for (i = 0; i < npoints; ++i) {
xNew = points.get(i).getBlockX();
@ -389,7 +407,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
- ((long) z2 - (long) z1) * (long) (targetX - x1);
if (crossproduct == 0) {
if ((z1 <= targetZ) == (targetZ <= z2)) return true; //on edge
if ((z1 <= targetZ) == (targetZ <= z2)) {
return true; //on edge
}
} else if (crossproduct < 0 && (x1 != targetX)) {
inside = !inside;
}
@ -457,7 +477,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
while (it.hasNext()) {
BlockVector2 current = it.next();
sb.append("(").append(current.getBlockX()).append(", ").append(current.getBlockZ()).append(")");
if (it.hasNext()) sb.append(" - ");
if (it.hasNext()) {
sb.append(" - ");
}
}
sb.append(" * (").append(minY).append(" - ").append(maxY).append(")");
return sb.toString();
@ -482,16 +504,24 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
@Override
public boolean containsEntireCuboid(int bx, int tx, int by, int ty, int bz, int tz) {
for (int x = bx; x <= tx; x++) {
if (!contains(x, 0, bz)) return false;
if (!contains(x, 0, bz)) {
return false;
}
}
for (int x = bx; x <= tx; x++) {
if (!contains(x, 0, tz)) return false;
if (!contains(x, 0, tz)) {
return false;
}
}
for (int z = bz; z <= tz; z++) {
if (!contains(bx, 0, z)) return false;
if (!contains(bx, 0, z)) {
return false;
}
}
for (int z = bz; z <= tz; z++) {
if (!contains(tx, 0, z)) return false;
if (!contains(tx, 0, z)) {
return false;
}
}
return true;
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -28,6 +28,8 @@ import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.extent.SingleRegionExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -85,19 +87,17 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
/**
* Get the number of blocks in the region.
*
* <p>Note: This method <b>must</b> be overridden.</p>
*
* @return number of blocks
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "getArea",
delegateParams = {}
)
default long getVolume() {
// TODO Remove default status when getArea is removed.
try {
if (getClass().getMethod("getArea").getDeclaringClass().equals(Region.class)) {
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
}
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
DeprecationUtil.checkDelegatingOverride(getClass());
return getArea();
}
@ -134,7 +134,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
* Expand the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
* @throws RegionOperationException if the operation cannot be performed
*/
void expand(BlockVector3... changes) throws RegionOperationException;
@ -142,7 +142,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
* Contract the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
* @throws RegionOperationException if the operation cannot be performed
*/
void contract(BlockVector3... changes) throws RegionOperationException;
@ -150,7 +150,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
* Shift the region.
*
* @param change the change
* @throws RegionOperationException
* @throws RegionOperationException if the operation cannot be performed
*/
void shift(BlockVector3 change) throws RegionOperationException;
@ -184,7 +184,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
Set<BlockVector2> getChunks();
/**
* Return a list of 16*16*16 chunks in a region
* Return a list of 16*16*16 chunks in a region.
*
* @return the chunk cubes this region overlaps with
*/
@ -232,7 +232,9 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
int maxSection = Math.min(15, getMaximumY() >> 4);
block = block.initChunk(chunk.getX(), chunk.getZ());
for (int layer = minSection; layer <= maxSection; layer++) {
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {
return;
}
block = block.initLayer(get, set, layer);
block.filter(filter, this);
}
@ -264,32 +266,38 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, boolean full) {
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {
return;
}
block = block.initLayer(get, set, layer);
block.filter(filter);
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean full) {
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {
return;
}
block = block.initLayer(get, set, layer);
block.filter(filter, minX, minY, minZ, maxX, maxY, maxZ);
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int yStart, int yEnd, boolean full) {
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {
return;
}
block = block.initLayer(get, set, layer);
block.filter(filter, yStart, yEnd);
}
default boolean containsEntireCuboid(int bx, int tx, int by, int ty, int bz, int tz) {
return contains(bx, by, bz) &&
contains(bx, by, tz) &&
contains(tx, by, bz) &&
contains(tx, by, tz) &&
contains(bx, ty, bz) &&
contains(bx, ty, tz) &&
contains(tx, ty, bz) &&
contains(tx, ty, tz);
return contains(bx, by, bz)
&& contains(bx, by, tz)
&& contains(tx, by, bz)
&& contains(tx, by, tz)
&& contains(bx, ty, bz)
&& contains(bx, ty, tz)
&& contains(tx, ty, bz)
&& contains(tx, ty, tz);
}
default boolean containsChunk(int chunkX, int chunkZ) {

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -26,6 +26,7 @@ import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.util.ArrayList;
@ -115,13 +116,13 @@ public class RegionIntersection extends AbstractRegion {
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
checkNotNull(changes);
throw new RegionOperationException("Cannot expand a region intersection");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.intersection.error.cannot-expand"));
}
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
checkNotNull(changes);
throw new RegionOperationException("Cannot contract a region intersection");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.intersection.error.cannot-contract"));
}
@Override
@ -137,14 +138,10 @@ public class RegionIntersection extends AbstractRegion {
return false;
}
@SuppressWarnings({"unchecked"})
@Override
public Iterator<BlockVector3> iterator() {
Iterator<BlockVector3>[] iterators = (Iterator<BlockVector3>[]) new Iterator[regions.size()];
for (int i = 0; i < regions.size(); i++) {
iterators[i] = regions.get(i).iterator();
}
return Iterators.concat(iterators);
return Iterators.concat(Iterators.transform(regions.iterator(), r -> r.iterator()));
}
@Override
@ -205,19 +202,31 @@ public class RegionIntersection extends AbstractRegion {
@Override
public boolean containsChunk(int chunkX, int chunkZ) {
for (Region region : regions) if (region.containsChunk(chunkX, chunkZ)) return true;
for (Region region : regions) {
if (region.containsChunk(chunkX, chunkZ)) {
return true;
}
}
return false;
}
@Override
public boolean contains(int x, int z) {
for (Region region : regions) if (region.contains(x, z)) return true;
for (Region region : regions) {
if (region.contains(x, z)) {
return true;
}
}
return false;
}
@Override
public boolean contains(int x, int y, int z) {
for (Region region : regions) if (region.contains(x, y, z)) return true;
for (Region region : regions) {
if (region.contains(x, y, z)) {
return true;
}
}
return false;
}
}

View File

@ -3,28 +3,34 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.util.formatting.text.Component;
public class RegionOperationException extends WorldEditException {
@Deprecated
public RegionOperationException(String msg) {
super(msg);
}
public RegionOperationException(Component msg) {
super(msg);
}
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -23,6 +23,8 @@ import com.google.common.collect.Lists;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.util.formatting.text.Component;
@ -144,19 +146,17 @@ public interface RegionSelector {
/**
* Get the number of blocks inside the region.
*
* <p>Note: This method <b>must</b> be overridden.</p>
*
* @return number of blocks, or -1 if undefined
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "getArea",
delegateParams = {}
)
default long getVolume() {
// TODO Remove default once getArea is removed
try {
if (getClass().getMethod("getArea").getDeclaringClass().equals(RegionSelector.class)) {
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
}
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
DeprecationUtil.checkDelegatingOverride(getClass());
return getArea();
}
@ -185,7 +185,7 @@ public interface RegionSelector {
@Deprecated
default List<String> getInformationLines() {
return Lists.newArrayList();
};
}
/**
* Get lines of information about the selection.

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
@ -24,6 +24,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import java.util.ArrayList;
@ -133,17 +134,17 @@ public class TransformRegion extends AbstractRegion {
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Can't expand a TransformedRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-expand"));
}
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Can't contract a TransformedRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-contract"));
}
@Override
public void shift(BlockVector3 change) throws RegionOperationException {
throw new RegionOperationException("Can't change a TransformedRegion");
throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-change"));
}
@Override

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.factory;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.factory;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.factory;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.factory;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.iterator;
@ -30,9 +30,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class FlatRegion3DIterator implements Iterator<BlockVector3> {
private Iterator<BlockVector2> flatIterator;
private int minY;
private int maxY;
private final Iterator<BlockVector2> flatIterator;
private final int minY;
private final int maxY;
private BlockVector2 next2D;
private int nextY;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.iterator;
@ -30,13 +30,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class FlatRegionIterator implements Iterator<BlockVector2> {
private Region region;
private int y;
private int minX;
private final Region region;
private final int y;
private final int minX;
private final int maxX;
private final int maxZ;
private int nextX;
private int nextZ;
private int maxX;
private int maxZ;
public FlatRegionIterator(Region region) {
checkNotNull(region);

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.iterator;
@ -68,7 +68,9 @@ public class RegionIterator implements Iterator<BlockVector3> {
@Override
public BlockVector3 next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
if (!hasNext()) {
throw new java.util.NoSuchElementException();
}
BlockVector3 answer = BlockVector3.at(nextX, nextY, nextZ);

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.polyhedron;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.polyhedron;
@ -28,10 +28,10 @@ public class Triangle {
private String tag = "Triangle";
private final Vector3[] vertices;
private final Vector3 normal;
private final double b;
private final double maxDotProduct;
/**
* Constructs a triangle with the given vertices (counter-clockwise)
* Constructs a triangle with the given vertices (counter-clockwise).
*
* @param v0 first vertex
* @param v1 second vertex
@ -45,7 +45,7 @@ public class Triangle {
vertices = new Vector3[] { v0, v1, v2 };
this.normal = v1.subtract(v0).cross(v2.subtract(v0)).normalize();
this.b = Math.max(Math.max(normal.dot(v0), normal.dot(v1)), normal.dot(v2));
this.maxDotProduct = Math.max(Math.max(normal.dot(v0), normal.dot(v1)), normal.dot(v2));
}
/**
@ -79,7 +79,7 @@ public class Triangle {
*/
public boolean below(Vector3 pt) {
checkNotNull(pt);
return normal.dot(pt) < b;
return normal.dot(pt) < maxDotProduct;
}
/**
@ -90,7 +90,7 @@ public class Triangle {
*/
public boolean above(Vector3 pt) {
checkNotNull(pt);
return normal.dot(pt) > b;
return normal.dot(pt) > maxDotProduct;
}
/**

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;
@ -51,7 +51,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class CylinderRegionSelector implements RegionSelector, CUIRegion {
protected static transient final NumberFormat NUMBER_FORMAT;
protected static final transient NumberFormat NUMBER_FORMAT;
protected transient CylinderRegion region;
static {

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;
@ -122,9 +122,9 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
region.setPos1(position1);
region.setPos2(position2);
assert(region.contains(o1));
assert(region.contains(o2));
assert(region.contains(position));
assert region.contains(o1);
assert region.contains(o2);
assert region.contains(position);
return true;
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector;
@ -53,7 +53,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
}
/**
* Create a new selector from another one
* Create a new selector from another one.
*
* @param oldSelector the old selector
*/

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector.limit;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector.limit;

View File

@ -3,76 +3,75 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import java.util.BitSet;
/**
* Generates solid and hollow shapes according to materials returned by the
* {@link #getBiome} method.
*/
public abstract class ArbitraryBiomeShape {
private final FlatRegion extent;
private int cacheOffsetX;
private int cacheOffsetZ;
private final Region extent;
private final int cacheOffsetX;
private final int cacheOffsetY;
private final 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());
}
BlockVector2 min = extent.getMinimumPoint().toBlockVector2();
BlockVector2 max = extent.getMaximumPoint().toBlockVector2();
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = max.getX() - cacheOffsetX + 2;
cacheSizeZ = max.getZ() - cacheOffsetZ + 2;
cache = new BiomeType[cacheSizeX * cacheSizeZ];
}
protected Iterable<BlockVector2> getExtent() {
return extent.asFlatRegion();
}
private final int cacheSizeX;
private final int cacheSizeY;
private final int cacheSizeZ;
/**
* Cache entries:
* Cache entries.
* null = unknown
* OUTSIDE = outside
* else = inside
*/
private final BiomeType[] cache;
private final BitSet isCached;
public ArbitraryBiomeShape(Region extent) {
this.extent = extent;
BlockVector3 min = extent.getMinimumPoint();
BlockVector3 max = extent.getMaximumPoint();
cacheOffsetX = min.getBlockX() - 1;
cacheOffsetY = min.getBlockY() - 1;
cacheOffsetZ = min.getBlockZ() - 1;
cacheSizeX = max.getX() - cacheOffsetX + 2;
cacheSizeY = max.getY() - cacheOffsetY + 2;
cacheSizeZ = max.getZ() - cacheOffsetZ + 2;
cache = new BiomeType[cacheSizeX * cacheSizeY * cacheSizeZ];
isCached = new BitSet(cache.length);
}
protected Iterable<BlockVector3> getExtent() {
return extent;
}
/**
* Override this function to specify the shape to generate.
@ -82,44 +81,37 @@ public abstract class ArbitraryBiomeShape {
* @param defaultBaseBiome 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 defaultBaseBiome);
protected abstract BiomeType getBiome(int x, int y, int z, BiomeType defaultBaseBiome);
private BiomeType getBiomeCached(int x, int z, BiomeType baseBiome) {
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, baseBiome);
if (material == null) {
// outside
cache[index] = BiomeTypes.THE_VOID;
return null;
}
private BiomeType getBiomeCached(int x, int y, int z, BiomeType baseBiome) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
if (!isCached.get(index)) {
final BiomeType material = getBiome(x, y, z, baseBiome);
isCached.set(index);
cache[index] = material;
return material;
}
if (cacheEntry == BiomeTypes.THE_VOID) {
// outside
return null;
}
return cacheEntry;
return cache[index];
}
private boolean isInsideCached(int x, int z, BiomeType baseBiome) {
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
private boolean isInsideCached(int x, int y, int z, BiomeType baseBiome) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * 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, baseBiome) != null;
return getBiomeCached(x, y, z, baseBiome) != null;
}
return cacheEntry != BiomeTypes.THE_VOID;
}
private boolean isOutside(int x, int y, int z, BiomeType baseBiome) {
return getBiomeCached(x, y, z, baseBiome) == null;
}
/**
* Generates the shape.
*
@ -131,13 +123,14 @@ public abstract class ArbitraryBiomeShape {
public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) {
int affected = 0;
for (BlockVector2 position : getExtent()) {
for (BlockVector3 position : getExtent()) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
if (!hollow) {
final BiomeType material = getBiome(x, z, baseBiome);
if (material != null && material != BiomeTypes.THE_VOID) {
final BiomeType material = getBiome(x, y, z, baseBiome);
if (material != null) {
editSession.getWorld().setBiome(position, material);
++affected;
}
@ -145,32 +138,12 @@ public abstract class ArbitraryBiomeShape {
continue;
}
final BiomeType material = getBiomeCached(x, z, baseBiome);
final BiomeType material = getBiomeCached(x, y, z, baseBiome);
if (material == null) {
continue;
}
boolean draw = false;
do {
if (!isInsideCached(x + 1, z, baseBiome)) {
draw = true;
break;
}
if (!isInsideCached(x - 1, z, baseBiome)) {
draw = true;
break;
}
if (!isInsideCached(x, z + 1, baseBiome)) {
draw = true;
break;
}
if (!isInsideCached(x, z - 1, baseBiome)) {
draw = true;
break;
}
} while (false);
if (!draw) {
if (!shouldDraw(x, y, z, material)) {
continue;
}
@ -181,4 +154,25 @@ public abstract class ArbitraryBiomeShape {
return affected;
}
private boolean shouldDraw(int x, int y, int z, BiomeType material) {
// we should draw this if the surrounding blocks fall outside the shape,
// this position will form an edge of the hull
if (isOutside(x + 1, y, z, material)) {
return true;
}
if (isOutside(x - 1, y, z, material)) {
return true;
}
if (isOutside(x, y, z + 1, material)) {
return true;
}
if (isOutside(x, y, z - 1, material)) {
return true;
}
if (isOutside(x, y + 1, z, material)) {
return true;
}
return isOutside(x, y - 1, z, material);
}
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;
@ -34,18 +34,22 @@ public abstract class ArbitraryShape {
protected final Region extent;
private int cacheOffsetX;
private int cacheOffsetY;
private int cacheOffsetZ;
private int cacheSizeX;
private int cacheSizeY;
private int cacheSizeZ;
private final int cacheOffsetX;
private final int cacheOffsetY;
private final int cacheOffsetZ;
private final int cacheSizeX;
private final int cacheSizeY;
private final int cacheSizeZ;
/**
* Cache entires:
* Cache for expression results.
*
* <p>
* Cache entries:
* 0 = unknown
* -1 = outside
* 1 = inside
* </p>
*/
private final byte[] cache;
@ -88,7 +92,7 @@ public abstract class ArbitraryShape {
* @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
* @throws MaxChangedBlocksException if the maximum blocks changed is exceeded
*/
public int generate(EditSession editSession, Pattern pattern, boolean hollow) throws MaxChangedBlocksException {
int affected = 0;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.shape;
@ -31,7 +31,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
private final Vector3 unit;
private final Vector3 zero2;
private Vector3 current = new MutableVector3(Vector3.ZERO);
private Extent extent;
private final Extent extent;
public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vector3 zero) {
this((Extent) editSession, unit, zero);
@ -52,31 +52,37 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
return current.add(x, y, z);
}
@SuppressWarnings("deprecation")
@Override
public int getBlockType(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
}
@SuppressWarnings("deprecation")
@Override
public int getBlockData(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
}
@SuppressWarnings("deprecation")
@Override
public int getBlockTypeAbs(double x, double y, double z) {
return extent.getBlock(BlockVector3.at(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
}
@SuppressWarnings("deprecation")
@Override
public int getBlockDataAbs(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
}
@SuppressWarnings("deprecation")
@Override
public int getBlockTypeRel(double x, double y, double z) {
return extent.getBlock(toWorldRel(x, y, z).toBlockPoint()).getBlockType().getLegacyCombinedId() >> 4;
}
@SuppressWarnings("deprecation")
@Override
public int getBlockDataRel(double x, double y, double z) {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world;
@ -64,9 +64,14 @@ public abstract class AbstractWorld implements World {
return null;
}
@Override
public int getMinY() {
return 0;
}
@Override
public int getMaxY() {
return getMaximumPoint().getBlockY();
return 255;
}
@Override
@ -124,12 +129,12 @@ public abstract class AbstractWorld implements World {
@Override
public BlockVector3 getMinimumPoint() {
return BlockVector3.at(-30000000, 0, -30000000);
return BlockVector3.at(-30000000, getMinY(), -30000000);
}
@Override
public BlockVector3 getMaximumPoint() {
return BlockVector3.at(30000000, 255, 30000000);
return BlockVector3.at(30000000, getMaxY(), 30000000);
}
@Override

View File

@ -99,6 +99,7 @@ public class NullWorld extends AbstractWorld {
public BiomeType getBiome(BlockVector2 position) {
return BiomeTypes.THE_VOID;
}
@Override
public BiomeType getBiomeType(int x, int y, int z) {
return BiomeTypes.THE_VOID;

View File

@ -100,7 +100,7 @@ public interface SimpleWorld extends World {
default void fixLighting(Iterable<BlockVector2> chunks) {
}
// @Override
// @Override
default boolean playEffect(BlockVector3 position, int type, int data) {
return false;
}

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* 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 Lesser General Public License
* for more details.
* 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world;
@ -71,6 +71,13 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
@Nullable
Path getStoragePath();
/**
* Get the minimum Y.
*
* @return the minimum Y
*/
int getMinY();
/**
* Get the maximum Y.
*
@ -324,11 +331,9 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
}
/**
* Refresh a specific chunk
* Refresh a specific chunk.
* Note: only 0 is guaranteed to send all tiles / entities
* Note: Only 65535 is guaranteed to send all blocks
* @param chunkX
* @param chunkZ
*/
void refreshChunk(final int chunkX, final int chunkZ);
@ -336,7 +341,7 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
IChunkGet get(int x, int z);
/**
* Send a fake chunk to a player/s
* Send a fake chunk to a player.
* @param player may be null to send to everyone
* @param packet the chunk packet
*/