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

View File

@ -55,9 +55,8 @@ public class FreeBuildRegion extends BukkitMaskManager {
World bukkitWorld = player.parent.getWorld(); World bukkitWorld = player.parent.getWorld();
AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
BlockVector3 vec1 = BlockVector3.at(0, 0, 0); Location pos1 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO);
Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1); Location pos2 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO);
Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec1);
AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0); AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0);
BlockBreakEvent event = new BlockBreakEvent(block, player.parent); 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) { public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) {
if (region.isOwner(localplayer) || region.isOwner(localplayer)) { if (region.isOwner(localplayer) || region.isOwner(localplayer.getName())) {
return true; return true;
} else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) { } else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) {
return true; return true;
@ -84,7 +84,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return true; return true;
} }
if (localplayer.hasPermission("fawe.worldguard.member")) { if (localplayer.hasPermission("fawe.worldguard.member")) {
if (region.isMember(localplayer) || region.isMember(localplayer)) { if (region.isMember(localplayer) || region.isMember(localplayer.getName())) {
return true; return true;
} else if (region.isMember("*")) { } else if (region.isMember("*")) {
return true; return true;

View File

@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override @Override
public boolean setBlockData(int x, int y, int z, BlockData blockData) { public boolean setBlockData(int x, int y, int z, BlockData blockData) {
try { try {
editSession.setBlock(BlockVector3.at(x, y, z), BukkitAdapter.adapt(blockData)); editSession.setBlock(x, y, z, BukkitAdapter.adapt(blockData));
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
return false; return false;
} }
@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override @Override
public BlockData getBlockData(int x, int y, int z) { 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 @Override
@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override @Override
public boolean isEmpty(int x, int y, int z) { 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("InhabitedTime", inhabitedTime);
out.writeNamedTag("LastUpdate", lastUpdate); out.writeNamedTag("LastUpdate", lastUpdate);
out.writeNamedTag("Biomes", biomes); if (hasBiomes) {
out.writeNamedTag("Biomes", biomes);
}
int len = 0; int len = 0;
for (boolean hasSection : hasSections) { for (boolean hasSection : hasSections) {
if (hasSection) { 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.command.tool.brush.Brush;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; 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.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;
public class ErodeBrush implements Brush { 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 @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { 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 x = tileChange.tag.getInt("x");
int y = tileChange.tag.getInt("y"); int y = tileChange.tag.getInt("y");
int z = tileChange.tag.getInt("z"); 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) { } catch (WorldEditException e) {

View File

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

View File

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

View File

@ -613,7 +613,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @param reorderMode The reorder mode * @param reorderMode The reorder mode
*/ */
public void setReorderMode(ReorderMode reorderMode) { 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. //TODO: Reorder mode.
@ -1106,7 +1106,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return height of highest block found or 'minY' * @return height of highest block found or 'minY'
*/ */
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { 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) { public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
for (int y = maxY; y >= minY; --y) { for (int y = maxY; y >= minY; --y) {
BlockVector3 pt = BlockVector3.at(x, y, z); if (filter.test(mutablebv.setComponents(x, y, z))) {
if (filter == null
? getBlock(pt).getBlockType().getMaterial().isMovementBlocker()
: filter.test(pt)) {
return y; return y;
} }
} }
@ -1583,7 +1585,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @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 { 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 getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, height - 1, 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); return setBlocks(region, pattern);
} }
@ -1670,7 +1672,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, -height + 1, 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); return setBlocks(region, pattern);
} }
@ -1745,7 +1747,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
position.add(adjustment.multiply(-1)), position.add(adjustment.multiply(-1)),
position.add(adjustment)); position.add(adjustment));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); Pattern pattern = (BlockTypes.AIR.getDefaultState());
return replaceBlocks(region, mask, pattern); 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 * @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 { 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException { 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException { 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 { public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(block); 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) { if (waterlogged) {
replace = new BlockReplace(this, new WaterloggedRemover(this)); replace = new BlockReplace(this, new WaterloggedRemover(this));
} else { } 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); RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), this);
@ -2228,7 +2230,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
blockMask blockMask
); );
BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState())); BlockReplace replace = new BlockReplace(this, (fluid.getDefaultState()));
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
// Around the origin in a 3x3 block // 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException { 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; int height = size;
@ -2595,19 +2599,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
for (int z = 0; z <= size; ++z) { for (int z = 0; z <= size; ++z) {
if ((filled && z <= size && x <= size) || z == size || x == size) { if ((filled && z <= size && x <= size) || z == size || x == size) {
setBlock(x + bx, y + by, z + bz, block);
if (setBlock(position.add(x, y, z), block)) { setBlock(-x + bx, y + by, z + bz, block);
++affected; setBlock(x + bx, y + by, -z + bz, block);
} setBlock(-x + bx, y + by, -z + bz, block);
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;
}
} }
} }
} }
@ -2643,16 +2638,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
continue; continue;
} }
for (int y = world.getMaxY(); y >= 1; --y) { for (int y = maxY; y >= 1; --y) {
BlockVector3 pt = BlockVector3.at(x, y, z); BlockType id = getBlock(x, y, z).getBlockType();
BlockType id = getBlock(pt).getBlockType();
if (id == BlockTypes.ICE) { if (id == BlockTypes.ICE) {
if (setBlock(pt, water)) { if (setBlock(x, y, z, water)) {
++affected; ++affected;
} }
} else if (id == BlockTypes.SNOW) { } else if (id == BlockTypes.SNOW) {
if (setBlock(pt, air)) { if (setBlock(x, y, z, air)) {
++affected; ++affected;
} }
} else if (id.getMaterial().isAir()) { } else if (id.getMaterial().isAir()) {
@ -2718,7 +2712,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
// Too high? // Too high?
if (y == world.getMaxY()) { if (y == maxY) {
break; break;
} }
@ -2743,13 +2737,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @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 { throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius; final double radiusSq = radius * radius;
final int ox = position.getBlockX(); final int ox = position.getBlockX();
final int oy = position.getBlockY();
final int oz = position.getBlockZ(); final int oz = position.getBlockZ();
final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState(); final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState();
@ -2765,20 +2757,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
continue; continue;
} }
loop: loop:
for (int y = world.getMaxY(); y >= 1; --y) { for (int y = maxY; y >= 1; --y) {
final BlockVector3 pt = BlockVector3.at(x, y, z); BlockType block = getBlockType(x, y, z);
final BlockState block = getBlock(pt); switch (block.getInternalId()) {
case BlockID.COARSE_DIRT:
if (block.getBlockType() == BlockTypes.DIRT || if (onlyNormalDirt) break loop;
(!onlyNormalDirt && block.getBlockType() == BlockTypes.COARSE_DIRT)) { case BlockID.DIRT:
if (setBlock(pt, grass)) { this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState());
break; break loop;
} case BlockID.WATER:
break; case BlockID.LAVA:
} else if (block.getBlockType() == BlockTypes.WATER || block.getBlockType() == BlockTypes.LAVA) { default:
break; if (block.getMaterial().isMovementBlocker()) {
} else if (block.getBlockType().getMaterial().isMovementBlocker()) { break loop;
break; }
} }
} }
} }
@ -2795,7 +2787,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of patches created * @return number of patches created
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @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 // We want to generate pumpkins
GardenPatchGenerator generator = new GardenPatchGenerator(this); GardenPatchGenerator generator = new GardenPatchGenerator(this);
generator.setPlant(GardenPatchGenerator.getPumpkinPattern()); generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
@ -2805,7 +2801,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
position.add(-apothem, -5, -apothem), position.add(-apothem, -5, -apothem),
position.add(apothem, 10, apothem)); position.add(apothem, 10, apothem));
double density = 0.02;
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator); GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground); 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.Switch;
import com.sk89q.worldedit.util.command.binding.Text; import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional; 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.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
@ -293,15 +294,15 @@ public class GenerationCommands extends MethodCommands {
@Command( @Command(
aliases = { "pumpkins" }, aliases = { "pumpkins" },
usage = "[size]", usage = "[size=10] [density=0.02]",
desc = "Generate pumpkin patches", desc = "Generate pumpkin patches",
min = 0, min = 0,
max = 2 max = 2
) )
@CommandPermissions("worldedit.generation.pumpkins") @CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION) @Logging(POSITION)
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException { 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); int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density);
BBC.COMMAND_PUMPKIN.send(player, affected); BBC.COMMAND_PUMPKIN.send(player, affected);
} }

View File

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

View File

@ -37,7 +37,7 @@ public class CylinderBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = (BlockTypes.COBBLESTONE.getDefaultState());
} }
editSession.makeCylinder(position, pattern, size, size, height, true); 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.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; 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.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Vector;
public class GravityBrush implements Brush { public class GravityBrush implements Brush {
private final boolean fullHeight; private final boolean fullHeight;
@ -35,21 +40,20 @@ public class GravityBrush implements Brush {
} }
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException {
double endY = position.getBlockY() + size; int size = (int) sizeDouble;
double startPerformY = Math.max(0, position.getBlockY() - size); int endY = position.getBlockY() + size;
double startCheckY = fullHeight ? 0 : startPerformY; int startPerformY = Math.max(0, position.getBlockY() - size);
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { int startCheckY = fullHeight ? 0 : startPerformY;
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
double freeSpot = startCheckY; for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
for (double y = startCheckY; y <= endY; ++y) { int freeSpot = startCheckY;
final BlockVector3 pt = BlockVector3.at(x, y, z); for (int y = startCheckY; y <= endY; y++) {
final BlockState block = editSession.getLazyBlock(pt); BlockStateHolder block = editSession.getLazyBlock(x, y, z);
if (!block.getBlockType().getMaterial().isAir()) { if (!block.getBlockType().getMaterial().isAir()) {
if (y != freeSpot) { if (y != freeSpot) {
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
final BlockVector3 pt2 = BlockVector3.at(x, freeSpot, z); editSession.setBlock(x, freeSpot, z, block);
editSession.setBlock(pt2, block);
} }
freeSpot = y + 1; freeSpot = y + 1;
} }

View File

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

View File

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

View File

@ -31,7 +31,7 @@ public class SphereBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = (BlockTypes.COBBLESTONE.getDefaultState());
} }
editSession.makeSphere(position, pattern, size, size, size, true); 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 Region region;
private BlockVector3 origin; private BlockVector3 origin;
private BaseBlock[][][] blocks;
private BiomeType[][] biomes = null;
public FaweClipboard IMP; public FaweClipboard IMP;
private BlockVector3 size; private BlockVector3 size;
private int mx;
private int my;
private int mz;
private final List<ClipboardEntity> entities = new ArrayList<>(); private final List<ClipboardEntity> entities = new ArrayList<>();
public BlockArrayClipboard(Region region) { public BlockArrayClipboard(Region region) {
@ -70,7 +71,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions(); 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.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.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.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.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.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) { public BlockArrayClipboard(Region region, FaweClipboard clipboard) {
@ -95,7 +100,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions(); this.size = getDimensions();
this.origin = region.getMinimumPoint(); this.origin = region.getMinimumPoint();
this.IMP = clipboard; 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) { public void init(Region region, FaweClipboard fc) {
@ -105,7 +112,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions(); this.size = getDimensions();
this.IMP = fc; this.IMP = fc;
this.origin = region.getMinimumPoint(); 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 @Override
@ -179,8 +188,10 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) { if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint()); int x = position.getBlockX() - mx;
return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState(); int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z).toImmutableState();
} }
return BlockTypes.AIR.getDefaultState(); return BlockTypes.AIR.getDefaultState();
@ -193,11 +204,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
if (region.contains(position)) { if(region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint()); int x = position.getBlockX() - mx;
return IMP.getBlock(v.getX(),v.getY(),v.getZ()); int y = position.getBlockY() - my;
} int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
}
return BlockTypes.AIR.getDefaultState().toBaseBlock(); return BlockTypes.AIR.getDefaultState().toBaseBlock();
} }
@ -212,50 +224,41 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
return false; 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) { public boolean setTile(BlockVector3 position, CompoundTag tag) {
BlockVector3 v = position.subtract(region.getMinimumPoint()); return setTile(position.getX(), position.getY(), position.getZ(), tag);
return IMP.setTile(v.getX(), v.getY(), v.getZ(), tag);
} }
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
BlockVector3 position = BlockVector3.at(x, y, z); x -= mx;
BlockVector3 v = position.subtract(region.getMinimumPoint()); y -= my;
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block); z -= mz;
return IMP.setBlock(x, y, z, block);
} }
@Override @Override
public boolean hasBiomes() { public boolean hasBiomes() {
return biomes != null; return IMP.hasBiomes();
} }
@Override @Override
public BiomeType getBiome(BlockVector2 position) { public BiomeType getBiome(BlockVector2 position) {
if (biomes != null BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
&& position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) { return IMP.getBiome(v.getX(), v.getZ());
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;
} }
@Override @Override
public boolean setBiome(BlockVector2 position, BiomeType biome) { public boolean setBiome(BlockVector2 position, BiomeType biome) {
if (position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) { int x = position.getBlockX() - mx;
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2()); int z = position.getBlockZ() - mz;
IMP.setBiome(v.getX(), v.getZ(), biome); return IMP.setBiome(x, z, biome);
if (biomes == null) {
biomes = new BiomeType[region.getWidth()][region.getLength()];
}
biomes[v.getBlockX()][v.getBlockZ()] = biome;
return true;
}
return false;
} }
@Nullable @Nullable

View File

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

View File

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

View File

@ -187,7 +187,7 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a pumpkin pattern * @return a pumpkin pattern
*/ */
public static Pattern getPumpkinPattern() { 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 * @return a melon pattern
*/ */
public static Pattern getMelonPattern() { 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. * A pattern that returns the same {@link BaseBlock} each time.
*/ */
@Deprecated
public class BlockPattern extends AbstractPattern { public class BlockPattern extends AbstractPattern {
private BaseBlock block; private BaseBlock block;
@ -37,6 +38,7 @@ public class BlockPattern extends AbstractPattern {
* *
* @param block the block * @param block the block
*/ */
@Deprecated
public BlockPattern(BlockStateHolder<?> block) { public BlockPattern(BlockStateHolder<?> block) {
setBlock(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.Operation;
import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import java.util.ArrayList; import java.util.ArrayList;
@ -243,6 +244,7 @@ public abstract class BreadthFirstSearch implements Operation {
@Override @Override
public Operation resume(RunContext run) throws WorldEditException { public Operation resume(RunContext run) throws WorldEditException {
MutableBlockVector3 mutable = new MutableBlockVector3();
IntegerTrio[] dirs = getIntDirections(); IntegerTrio[] dirs = getIntDirections();
BlockVectorSet tempQueue = new BlockVectorSet(); BlockVectorSet tempQueue = new BlockVectorSet();
BlockVectorSet chunkLoadSet = new BlockVectorSet(); BlockVectorSet chunkLoadSet = new BlockVectorSet();
@ -280,7 +282,7 @@ public abstract class BreadthFirstSearch implements Operation {
int x = from.getBlockX() + direction.x; int x = from.getBlockX() + direction.x;
int z = from.getBlockZ() + direction.z; int z = from.getBlockZ() + direction.z;
if (!visited.contains(x, y, z)) { if (!visited.contains(x, y, z)) {
if (isVisitable(from, BlockVector3.at(x, y, z))) { if (isVisitable(from, mutable.setComponents(x, y, z))) {
j++; j++;
visited.add(x, y, z); visited.add(x, y, z);
tempQueue.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)); BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr));
// Skip water/lava // Skip water/lava
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) { if (existing.getBlockType().getMaterial().isMovementBlocker()) {
int y0 = newHeight - 1; int y0 = newHeight - 1;
for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) { for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) {
BlockState get = session.getBlock(xr, getY, zr); BlockState get = session.getBlock(xr, getY, zr);

View File

@ -67,9 +67,9 @@ public class IntegerProperty extends AbstractProperty<Integer> {
public Integer getValueFor(String string) { public Integer getValueFor(String string) {
try { try {
int val = Integer.parseInt(string); int val = Integer.parseInt(string);
if (!getValues().contains(val)) { // if (!getValues().contains(val)) { // This check is slow
throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString()); // throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString());
} // }
return val; return val;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid int value: " + string + ". Not an int."); 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 int right;
private final BlockVector3 blockPoint; private final BlockVector3 blockPoint;
private static HashMap<CharSequence, Direction> map = new HashMap<>(); private static HashMap<String, Direction> map = new HashMap<>();
static { static {
for (Direction dir : Direction.values()) { for (Direction dir : Direction.values()) {
@ -79,7 +79,7 @@ public enum Direction {
} }
Direction(Vector3 vector, int flags, int left, int right) { 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.direction = vector.normalize();
this.flags = flags; this.flags = flags;
this.left = left; this.left = left;
@ -98,6 +98,30 @@ public enum Direction {
return right != -1 ? values()[right] : null; 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 * Return true if the direction is of a cardinal direction (north, west
* east, and south). * east, and south).