This commit is contained in:
Jesse Boyd 2019-06-29 00:01:51 +10:00
parent 3b2031c22c
commit 846a1b0769
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
26 changed files with 192 additions and 154 deletions

View File

@ -6,6 +6,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.thevoxelbox.voxelsniper.Message;
import com.thevoxelbox.voxelsniper.SnipeData;
@ -13,6 +14,7 @@ public class PatternPerformer extends vPerformer {
private String info;
private Pattern pattern;
private Extent extent;
private final MutableBlockVector3 mutable = new MutableBlockVector3();
@Override
public void info(Message vm) {
@ -31,7 +33,7 @@ public class PatternPerformer extends vPerformer {
@Override
public void perform(AsyncBlock block) {
BlockVector3 bv = BlockVector3.at(block.getX(), block.getY(), block.getZ());
BlockVector3 bv = mutable.setComponents(block.getX(), block.getY(), block.getZ());
try {
pattern.apply(extent, bv, bv);
} catch (WorldEditException e) {

View File

@ -55,9 +55,8 @@ public class FreeBuildRegion extends BukkitMaskManager {
World bukkitWorld = player.parent.getWorld();
AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
BlockVector3 vec1 = BlockVector3.at(0, 0, 0);
Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1);
Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec1);
Location pos1 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO);
Location pos2 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO);
AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0);
BlockBreakEvent event = new BlockBreakEvent(block, player.parent);

View File

@ -74,7 +74,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
}
public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) {
if (region.isOwner(localplayer) || region.isOwner(localplayer)) {
if (region.isOwner(localplayer) || region.isOwner(localplayer.getName())) {
return true;
} else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) {
return true;
@ -84,7 +84,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return true;
}
if (localplayer.hasPermission("fawe.worldguard.member")) {
if (region.isMember(localplayer) || region.isMember(localplayer)) {
if (region.isMember(localplayer) || region.isMember(localplayer.getName())) {
return true;
} else if (region.isMember("*")) {
return true;

View File

@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try {
editSession.setBlock(BlockVector3.at(x, y, z), BukkitAdapter.adapt(blockData));
editSession.setBlock(x, y, z, BukkitAdapter.adapt(blockData));
} catch (MaxChangedBlocksException e) {
return false;
}
@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public BlockData getBlockData(int x, int y, int z) {
return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z)));
return BukkitAdapter.adapt(editSession.getBlock(x, y, z));
}
@Override
@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir();
return editSession.getBlock(x, y, z).getBlockType().getMaterial().isAir();
}
}

View File

@ -108,7 +108,9 @@ public class WritableMCAChunk extends FaweChunk<Void> {
}
out.writeNamedTag("InhabitedTime", inhabitedTime);
out.writeNamedTag("LastUpdate", lastUpdate);
out.writeNamedTag("Biomes", biomes);
if (hasBiomes) {
out.writeNamedTag("Biomes", biomes);
}
int len = 0;
for (boolean hasSection : hasSections) {
if (hasSection) {

View File

@ -8,14 +8,17 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;
public class ErodeBrush implements Brush {
private static final BlockVector3[] FACES_TO_CHECK = {BlockVector3.at(0, 0, 1), BlockVector3.at(0, 0, -1), BlockVector3.at(0, 1, 0), BlockVector3.at(0, -1, 0), BlockVector3.at(1, 0, 0), BlockVector3.at(-1, 0, 0)};
private static final BlockVector3[] FACES_TO_CHECK = Direction.valuesOf(Direction.Flag.CARDINAL).stream().map(direction -> direction.toBlockVector()).toArray(size -> new BlockVector3[size]);
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {

View File

@ -77,7 +77,7 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory {
int x = tileChange.tag.getInt("x");
int y = tileChange.tag.getInt("y");
int z = tileChange.tag.getInt("z");
clipboard.setTile(BlockVector3.at(x,y,z), tileChange.tag);
clipboard.setTile(x,y,z, tileChange.tag);
}
}
} catch (WorldEditException e) {

View File

@ -19,6 +19,7 @@ import java.util.*;
*/
public class BlockVectorSet extends AbstractCollection<BlockVector3> implements Set<BlockVector3> {
private Int2ObjectMap<LocalBlockVectorSet> localSets = new Int2ObjectOpenHashMap<>();
private MutableBlockVector3 mutable = new MutableBlockVector3();
@Override
public int size() {
@ -37,12 +38,12 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
int newSize = count + size;
if (newSize > index) {
int localIndex = index - count;
MutableBlockVector3 pos = new MutableBlockVector3(set.getIndex(localIndex));
BlockVector3 pos = mutable.setComponents(set.getIndex(localIndex));
int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair);
pos.mutX((cx << 11) + pos.getBlockX());
pos.mutZ((cz << 11) + pos.getBlockZ());
pos = pos.mutX((cx << 11) + pos.getBlockX());
pos = pos.mutZ((cz << 11) + pos.getBlockZ());
return pos;
}
count += newSize;

View File

@ -54,7 +54,7 @@ public class EditSessionBuilder {
public EditSessionBuilder(@Nonnull World world) {
checkNotNull(world);
this.world = world;
this.worldName = world.getName();
this.worldName = Fawe.imp().getWorldName(world);
}
public EditSessionBuilder(@Nonnull String worldName) {

View File

@ -613,7 +613,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @param reorderMode The reorder mode
*/
public void setReorderMode(ReorderMode reorderMode) {
//TODO Not working yet.
//TODO Not working yet. - It shouldn't need to work. FAWE doesn't need reordering.
}
//TODO: Reorder mode.
@ -1106,7 +1106,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return height of highest block found or 'minY'
*/
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
return getHighestTerrainBlock(x, z, minY, maxY, null);
for (int y = maxY; y >= minY; --y) {
if (getBlock(x, y, z).getBlockType().getMaterial().isMovementBlocker()) {
return y;
}
}
return minY;
}
/**
@ -1121,10 +1126,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
*/
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
for (int y = maxY; y >= minY; --y) {
BlockVector3 pt = BlockVector3.at(x, y, z);
if (filter == null
? getBlock(pt).getBlockType().getMaterial().isMovementBlocker()
: filter.test(pt)) {
if (filter.test(mutablebv.setComponents(x, y, z))) {
return y;
}
}
@ -1583,7 +1585,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public <B extends BlockStateHolder<B>> int fillXZ(BlockVector3 origin, B block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
return fillXZ(origin, new BlockPattern(block), radius, depth, recursive);
return fillXZ(origin, (block), radius, depth, recursive);
}
/**
@ -1648,7 +1650,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, height - 1, apothem - 1));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
Pattern pattern = (BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
}
@ -1670,7 +1672,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, -height + 1, apothem - 1));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
Pattern pattern = (BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
}
@ -1745,7 +1747,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range
position.add(adjustment.multiply(-1)),
position.add(adjustment));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
Pattern pattern = (BlockTypes.AIR.getDefaultState());
return replaceBlocks(region, mask, pattern);
}
@ -1817,7 +1819,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException {
return replaceBlocks(region, filter, new BlockPattern(replacement));
return replaceBlocks(region, filter, (replacement));
}
/**
@ -1889,7 +1891,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public <B extends BlockStateHolder<B>> int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException {
return makeCuboidFaces(region, new BlockPattern(block));
return makeCuboidFaces(region, (block));
}
/**
@ -1941,7 +1943,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public <B extends BlockStateHolder<B>> int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException {
return makeCuboidWalls(region, new BlockPattern(block));
return makeCuboidWalls(region, (block));
}
/**
@ -2003,7 +2005,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(block);
return overlayCuboidBlocks(region, new BlockPattern(block));
return overlayCuboidBlocks(region, (block));
}
/**
@ -2186,7 +2188,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
if (waterlogged) {
replace = new BlockReplace(this, new WaterloggedRemover(this));
} else {
replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState()));
replace = new BlockReplace(this, (BlockTypes.AIR.getDefaultState()));
}
RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), this);
@ -2228,7 +2230,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
blockMask
);
BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState()));
BlockReplace replace = new BlockReplace(this, (fluid.getDefaultState()));
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
// Around the origin in a 3x3 block
@ -2585,7 +2587,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException {
int affected = 0;
int bx = position.getX();
int by = position.getY();
int bz = position.getZ();
int height = size;
@ -2595,19 +2599,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
for (int z = 0; z <= size; ++z) {
if ((filled && z <= size && x <= size) || z == size || x == size) {
if (setBlock(position.add(x, y, z), block)) {
++affected;
}
if (setBlock(position.add(-x, y, z), block)) {
++affected;
}
if (setBlock(position.add(x, y, -z), block)) {
++affected;
}
if (setBlock(position.add(-x, y, -z), block)) {
++affected;
}
setBlock(x + bx, y + by, z + bz, block);
setBlock(-x + bx, y + by, z + bz, block);
setBlock(x + bx, y + by, -z + bz, block);
setBlock(-x + bx, y + by, -z + bz, block);
}
}
}
@ -2643,16 +2638,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
continue;
}
for (int y = world.getMaxY(); y >= 1; --y) {
BlockVector3 pt = BlockVector3.at(x, y, z);
BlockType id = getBlock(pt).getBlockType();
for (int y = maxY; y >= 1; --y) {
BlockType id = getBlock(x, y, z).getBlockType();
if (id == BlockTypes.ICE) {
if (setBlock(pt, water)) {
if (setBlock(x, y, z, water)) {
++affected;
}
} else if (id == BlockTypes.SNOW) {
if (setBlock(pt, air)) {
if (setBlock(x, y, z, air)) {
++affected;
}
} else if (id.getMaterial().isAir()) {
@ -2718,7 +2712,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
// Too high?
if (y == world.getMaxY()) {
if (y == maxY) {
break;
}
@ -2743,13 +2737,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int green(BlockVector3 position, double radius, boolean onlyNormalDirt)
public int green(BlockVector3 position, double radius, final boolean onlyNormalDirt)
throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius;
final int ox = position.getBlockX();
final int oy = position.getBlockY();
final int oz = position.getBlockZ();
final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState();
@ -2765,20 +2757,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
continue;
}
loop:
for (int y = world.getMaxY(); y >= 1; --y) {
final BlockVector3 pt = BlockVector3.at(x, y, z);
final BlockState block = getBlock(pt);
if (block.getBlockType() == BlockTypes.DIRT ||
(!onlyNormalDirt && block.getBlockType() == BlockTypes.COARSE_DIRT)) {
if (setBlock(pt, grass)) {
break;
}
break;
} else if (block.getBlockType() == BlockTypes.WATER || block.getBlockType() == BlockTypes.LAVA) {
break;
} else if (block.getBlockType().getMaterial().isMovementBlocker()) {
break;
for (int y = maxY; y >= 1; --y) {
BlockType block = getBlockType(x, y, z);
switch (block.getInternalId()) {
case BlockID.COARSE_DIRT:
if (onlyNormalDirt) break loop;
case BlockID.DIRT:
this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState());
break loop;
case BlockID.WATER:
case BlockID.LAVA:
default:
if (block.getMaterial().isMovementBlocker()) {
break loop;
}
}
}
}
@ -2795,7 +2787,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of patches created
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int makePumpkinPatches(BlockVector3 position, int apothem) throws MaxChangedBlocksException {
public int makePumpkinPatches(final BlockVector3 position, final int apothem) {
return makePumpkinPatches(position, apothem, 0.02);
}
public int makePumpkinPatches(final BlockVector3 position, final int apothem, double density) {
// We want to generate pumpkins
GardenPatchGenerator generator = new GardenPatchGenerator(this);
generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
@ -2805,7 +2801,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range
position.add(-apothem, -5, -apothem),
position.add(apothem, 10, apothem));
double density = 0.02;
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground);

View File

@ -53,6 +53,7 @@ import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.command.parametric.ParameterException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockType;
@ -293,15 +294,15 @@ public class GenerationCommands extends MethodCommands {
@Command(
aliases = { "pumpkins" },
usage = "[size]",
usage = "[size=10] [density=0.02]",
desc = "Generate pumpkin patches",
min = 0,
max = 2
)
@CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION)
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem);
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem, @Optional("0.02") double density) throws WorldEditException, ParameterException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density);
BBC.COMMAND_PUMPKIN.send(player, affected);
}

View File

@ -76,7 +76,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
BlockState targetBlock = editSession.getBlock(clicked.toVector().toBlockPoint());
if (targetBlock != null) {
pattern = new BlockPattern(targetBlock);
pattern = (targetBlock);
player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName());
}

View File

@ -37,7 +37,7 @@ public class CylinderBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeCylinder(position, pattern, size, size, height, true);
}

View File

@ -21,11 +21,16 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Vector;
public class GravityBrush implements Brush {
private final boolean fullHeight;
@ -35,21 +40,20 @@ public class GravityBrush implements Brush {
}
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
double endY = position.getBlockY() + size;
double startPerformY = Math.max(0, position.getBlockY() - size);
double startCheckY = fullHeight ? 0 : startPerformY;
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
double freeSpot = startCheckY;
for (double y = startCheckY; y <= endY; ++y) {
final BlockVector3 pt = BlockVector3.at(x, y, z);
final BlockState block = editSession.getLazyBlock(pt);
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException {
int size = (int) sizeDouble;
int endY = position.getBlockY() + size;
int startPerformY = Math.max(0, position.getBlockY() - size);
int startCheckY = fullHeight ? 0 : startPerformY;
for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
int freeSpot = startCheckY;
for (int y = startCheckY; y <= endY; y++) {
BlockStateHolder block = editSession.getLazyBlock(x, y, z);
if (!block.getBlockType().getMaterial().isAir()) {
if (y != freeSpot) {
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
final BlockVector3 pt2 = BlockVector3.at(x, freeSpot, z);
editSession.setBlock(pt2, block);
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
editSession.setBlock(x, freeSpot, z, block);
}
freeSpot = y + 1;
}

View File

@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeCylinder(position, pattern, size, size, height, false);
}

View File

@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeSphere(position, pattern, size, size, size, false);
}

View File

@ -31,7 +31,7 @@ public class SphereBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeSphere(position, pattern, size, size, size, true);
}

View File

@ -58,10 +58,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
private Region region;
private BlockVector3 origin;
private BaseBlock[][][] blocks;
private BiomeType[][] biomes = null;
public FaweClipboard IMP;
private BlockVector3 size;
private int mx;
private int my;
private int mz;
private final List<ClipboardEntity> entities = new ArrayList<>();
public BlockArrayClipboard(Region region) {
@ -70,7 +71,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
this.origin = region.getMinimumPoint();
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
}
/**
@ -86,7 +89,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
this.origin = region.getMinimumPoint();
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
}
public BlockArrayClipboard(Region region, FaweClipboard clipboard) {
@ -95,7 +100,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.origin = region.getMinimumPoint();
this.IMP = clipboard;
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
}
public void init(Region region, FaweClipboard fc) {
@ -105,7 +112,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = fc;
this.origin = region.getMinimumPoint();
this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
}
@Override
@ -179,8 +188,10 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState();
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z).toImmutableState();
}
return BlockTypes.AIR.getDefaultState();
@ -193,11 +204,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ());
}
if(region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
}
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@ -212,50 +224,41 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
return false;
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {
x -= mx;
y -= my;
z -= mz;
return IMP.setTile(x, y, z, tag);
}
public boolean setTile(BlockVector3 position, CompoundTag tag) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setTile(v.getX(), v.getY(), v.getZ(), tag);
return setTile(position.getX(), position.getY(), position.getZ(), tag);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
BlockVector3 position = BlockVector3.at(x, y, z);
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block);
x -= mx;
y -= my;
z -= mz;
return IMP.setBlock(x, y, z, block);
}
@Override
public boolean hasBiomes() {
return biomes != null;
return IMP.hasBiomes();
}
@Override
public BiomeType getBiome(BlockVector2 position) {
if (biomes != null
&& position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
BiomeType biomeType = biomes[v.getBlockX()][v.getBlockZ()];
if (biomeType != null) {
return IMP.getBiome(v.getX(), v.getZ());
//TODO Remove the line above and replace with this: return biomeType;
}
return IMP.getBiome(v.getX(), v.getZ());
}
return BiomeTypes.OCEAN;
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
return IMP.getBiome(v.getX(), v.getZ());
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
if (position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
IMP.setBiome(v.getX(), v.getZ(), biome);
if (biomes == null) {
biomes = new BiomeType[region.getWidth()][region.getLength()];
}
biomes[v.getBlockX()][v.getBlockZ()] = biome;
return true;
}
return false;
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
return IMP.setBiome(x, z, biome);
}
@Nullable

View File

@ -82,8 +82,13 @@ public class BlockBagExtent extends AbstractDelegateExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return setBlock(position.getX(), position.getY(), position.getZ(), block);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if (blockBag != null) {
BlockState existing = getExtent().getBlock(position);
BlockState existing = getLazyBlock(x, y, z);
if (!block.getBlockType().equals(existing.getBlockType())) {
if (!block.getBlockType().getMaterial().isAir()) {
@ -110,11 +115,6 @@ public class BlockBagExtent extends AbstractDelegateExtent {
}
}
return super.setBlock(position, block);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return setBlock(BlockVector3.at(x,y,z),block);
return super.setBlock(x, y, z, block);
}
}

View File

@ -83,9 +83,9 @@ public class FloraGenerator implements RegionFunction {
*/
public static Pattern getDesertPattern() {
RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(BlockTypes.DEAD_BUSH.getDefaultState()), 30);
pattern.add(new BlockPattern(BlockTypes.CACTUS.getDefaultState()), 20);
pattern.add(new BlockPattern(BlockTypes.AIR.getDefaultState()), 300);
pattern.add((BlockTypes.DEAD_BUSH.getDefaultState()), 30);
pattern.add((BlockTypes.CACTUS.getDefaultState()), 20);
pattern.add((BlockTypes.AIR.getDefaultState()), 300);
return pattern;
}
@ -96,9 +96,9 @@ public class FloraGenerator implements RegionFunction {
*/
public static Pattern getTemperatePattern() {
RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300);
pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5);
pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5);
pattern.add((BlockTypes.GRASS.getDefaultState()), 300);
pattern.add((BlockTypes.POPPY.getDefaultState()), 5);
pattern.add((BlockTypes.DANDELION.getDefaultState()), 5);
return pattern;
}

View File

@ -187,7 +187,7 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a pumpkin pattern
*/
public static Pattern getPumpkinPattern() {
return new BlockPattern(BlockTypes.PUMPKIN.getDefaultState());
return (BlockTypes.PUMPKIN.getDefaultState());
}
/**
@ -208,6 +208,6 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a melon pattern
*/
public static Pattern getMelonPattern() {
return new BlockPattern(BlockTypes.MELON.getDefaultState());
return (BlockTypes.MELON.getDefaultState());
}
}

View File

@ -28,6 +28,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
/**
* A pattern that returns the same {@link BaseBlock} each time.
*/
@Deprecated
public class BlockPattern extends AbstractPattern {
private BaseBlock block;
@ -37,6 +38,7 @@ public class BlockPattern extends AbstractPattern {
*
* @param block the block
*/
@Deprecated
public BlockPattern(BlockStateHolder<?> block) {
setBlock(block);
}

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.util.Direction;
import java.util.ArrayList;
@ -243,6 +244,7 @@ public abstract class BreadthFirstSearch implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
MutableBlockVector3 mutable = new MutableBlockVector3();
IntegerTrio[] dirs = getIntDirections();
BlockVectorSet tempQueue = new BlockVectorSet();
BlockVectorSet chunkLoadSet = new BlockVectorSet();
@ -280,7 +282,7 @@ public abstract class BreadthFirstSearch implements Operation {
int x = from.getBlockX() + direction.x;
int z = from.getBlockZ() + direction.z;
if (!visited.contains(x, y, z)) {
if (isVisitable(from, BlockVector3.at(x, y, z))) {
if (isVisitable(from, mutable.setComponents(x, y, z))) {
j++;
visited.add(x, y, z);
tempQueue.add(x, y, z);

View File

@ -287,7 +287,7 @@ public class HeightMap {
BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr));
// Skip water/lava
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
if (existing.getBlockType().getMaterial().isMovementBlocker()) {
int y0 = newHeight - 1;
for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) {
BlockState get = session.getBlock(xr, getY, zr);

View File

@ -67,9 +67,9 @@ public class IntegerProperty extends AbstractProperty<Integer> {
public Integer getValueFor(String string) {
try {
int val = Integer.parseInt(string);
if (!getValues().contains(val)) {
throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString());
}
// if (!getValues().contains(val)) { // This check is slow
// throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString());
// }
return val;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid int value: " + string + ". Not an int.");

View File

@ -69,7 +69,7 @@ public enum Direction {
private final int right;
private final BlockVector3 blockPoint;
private static HashMap<CharSequence, Direction> map = new HashMap<>();
private static HashMap<String, Direction> map = new HashMap<>();
static {
for (Direction dir : Direction.values()) {
@ -79,7 +79,7 @@ public enum Direction {
}
Direction(Vector3 vector, int flags, int left, int right) {
this.blockPoint = vector.toBlockPoint();
this.blockPoint = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.direction = vector.normalize();
this.flags = flags;
this.left = left;
@ -98,6 +98,30 @@ public enum Direction {
return right != -1 ? values()[right] : null;
}
public double getX() {
return direction.getX();
}
public double getY() {
return direction.getY();
}
public double getZ() {
return direction.getZ();
}
public int getBlockX() {
return blockPoint.getX();
}
public int getBlockY() {
return blockPoint.getY();
}
public int getBlockZ() {
return blockPoint.getZ();
}
/**
* Return true if the direction is of a cardinal direction (north, west
* east, and south).