minor tweak for mutable vectors

This commit is contained in:
Jesse Boyd
2019-04-01 03:09:20 +11:00
parent 2165bb127f
commit 92a7bd5e44
120 changed files with 923 additions and 2426 deletions

View File

@ -136,8 +136,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
private FawePlayer player;
private FaweChangeSet changeTask;
private MutableBlockVector mutablebv = new MutableBlockVector();
private MutableVector mutablev = new MutableVector();
private MutableBlockVector3 mutablebv = new MutableBlockVector3();
private int changes = 0;
private BlockBag blockBag;
@ -1080,7 +1079,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
public boolean setBlock(int x, int y, int z, Pattern pattern) {
this.changes++;
try {
BlockVector3 bv = mutablebv.setComponents(x, y, z).toBlockVector3();
BlockVector3 bv = mutablebv.setComponents(x, y, z);
return pattern.apply(extent, bv, bv);
} catch (WorldEditException e) {
throw new RuntimeException("Unexpected exception", e);
@ -2147,7 +2146,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
private int makeCylinder(BlockVector3 pos, final Pattern block, double radiusX, double radiusZ, int height, double thickness, final boolean filled) {
radiusX += 0.5;
radiusZ += 0.5;
MutableBlockVector posv = new MutableBlockVector(pos);
MutableBlockVector3 posv = new MutableBlockVector3(pos);
if (height == 0) {
return this.changes;
} else if (height < 0) {
@ -2167,7 +2166,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
int px = posv.getBlockX();
int py = posv.getBlockY();
int pz = posv.getBlockZ();
MutableBlockVector mutable = new MutableBlockVector();
MutableBlockVector3 mutable = new MutableBlockVector3();
final int ceilRadiusX = (int) Math.ceil(radiusX);
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
@ -2207,10 +2206,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
for (int y = 0; y < height; ++y) {
this.setBlock(mutable.setComponents(px + x, py + y, pz + z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz + z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz - z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz - z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz + z), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz + z), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz - z), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz - z), block);
}
}
}
@ -2241,10 +2240,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
for (int y = 0; y < height; ++y) {
this.setBlock(mutable.setComponents(px + x, py + y, pz + z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz + z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz - z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz - z).toBlockVector3(), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz + z), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz + z), block);
this.setBlock(mutable.setComponents(px + x, py + y, pz - z), block);
this.setBlock(mutable.setComponents(px - x, py + y, pz - z), block);
}
}
}
@ -2271,7 +2270,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
int px = pos.getBlockX();
int py = pos.getBlockY();
int pz = pos.getBlockZ();
MutableBlockVector mutable = new MutableBlockVector();
MutableBlockVector3 mutable = new MutableBlockVector3();
final int ceilRadiusX = (int) Math.ceil(radiusX);
final int ceilRadiusY = (int) Math.ceil(radiusY);
@ -2318,21 +2317,21 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
if (Math.abs((x) * nx + (y) * ny + (z) * nz) < threshold)
setBlock(mutable.setComponents(px + x, py + y, pz + z).toBlockVector3(), block);
setBlock(mutable.setComponents(px + x, py + y, pz + z), block);
if (Math.abs((-x) * nx + (y) * ny + (z) * nz) < threshold)
setBlock(mutable.setComponents(px - x, py + y, pz + z).toBlockVector3(), block);
setBlock(mutable.setComponents(px - x, py + y, pz + z), block);
if (Math.abs((x) * nx + (-y) * ny + (z) * nz) < threshold)
setBlock(mutable.setComponents(px + x, py - y, pz + z).toBlockVector3(), block);
setBlock(mutable.setComponents(px + x, py - y, pz + z), block);
if (Math.abs((x) * nx + (y) * ny + (-z) * nz) < threshold)
setBlock(mutable.setComponents(px + x, py + y, pz - z).toBlockVector3(), block);
setBlock(mutable.setComponents(px + x, py + y, pz - z), block);
if (Math.abs((-x) * nx + (-y) * ny + (z) * nz) < threshold)
setBlock(mutable.setComponents(px - x, py - y, pz + z).toBlockVector3(), block);
setBlock(mutable.setComponents(px - x, py - y, pz + z), block);
if (Math.abs((x) * nx + (-y) * ny + (-z) * nz) < threshold)
setBlock(mutable.setComponents(px + x, py - y, pz - z).toBlockVector3(), block);
setBlock(mutable.setComponents(px + x, py - y, pz - z), block);
if (Math.abs((-x) * nx + (y) * ny + (-z) * nz) < threshold)
setBlock(mutable.setComponents(px - x, py + y, pz - z).toBlockVector3(), block);
setBlock(mutable.setComponents(px - x, py + y, pz - z), block);
if (Math.abs((-x) * nx + (-y) * ny + (-z) * nz) < threshold)
setBlock(mutable.setComponents(px - x, py - y, pz - z).toBlockVector3(), block);
setBlock(mutable.setComponents(px - x, py - y, pz - z), block);
}
}
}
@ -2791,7 +2790,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
final int maxY = max.getBlockY();
final int maxZ = max.getBlockZ();
MutableBlockVector mutable = new MutableBlockVector(minX, minY, minZ);
MutableBlockVector3 mutable = new MutableBlockVector3(minX, minY, minZ);
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
@ -2938,14 +2937,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
//
// for (BlockVector3 position : region) {
// // offset, scale
// final Vector3 scaled = position.toVector3().subtract(zero).divide(unit);
// final Vector3 scaled = position.subtract(zero).divide(unit);
//
// // transform
// expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ());
//
// final BlockVector3 sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue());
private MutableBlockVector mutable = new MutableBlockVector();
private MutableBlockVector3 mutable = new MutableBlockVector3();
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
@ -3297,12 +3296,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
@Override
protected BaseBiome getBiome(final int x, final int z, final BaseBiome defaultBiomeType) {
final Vector2 current = Vector2.at(x, z);
environment.setCurrentBlock(current.toVector3(0));
final Vector2 scaled = current.subtract(zero2D).divide(unit2D);
environment.setCurrentBlock(x, 0, z);
double scaledX = (x - zero2D.getX()) / unit2D.getX();
double scaledZ = (z - zero2D.getZ()) / unit2D.getZ();
try {
if (expression.evaluate(scaled.getX(), scaled.getZ()) <= 0) {
if (expression.evaluate(scaledX, scaledZ) <= 0) {
return null;
}
@ -3397,8 +3396,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
}
final Set<BlockVector2> chunks = region.getChunks();
MutableBlockVector mutable = new MutableBlockVector();
MutableBlockVector2D mutable2D = new MutableBlockVector2D();
MutableBlockVector3 mutable = new MutableBlockVector3();
MutableBlockVector2 mutable2D = new MutableBlockVector2();
for (BlockVector2 chunk : chunks) {
final int cx = chunk.getBlockX();
final int cz = chunk.getBlockZ();
@ -3418,7 +3417,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
boolean containsAny = false;
if (cuboid && containsBot1 && containsBot2 && containsTop1 && containsTop2 && conNextX && conNextZ) {
containsAny = true;
BlockVector3 mbv = mutable.toBlockVector3();
BlockVector3 mbv = mutable;
if (fcs != null) {
for (int x = 0; x < 16; x++) {
int xx = x + bx;

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweLimit;
@ -43,7 +42,6 @@ import com.sk89q.jchronic.utils.Time;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.command.tool.*;
@ -51,7 +49,6 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.operation.ChangeSetExecutor;
import com.sk89q.worldedit.history.changeset.ChangeSet;
import com.sk89q.worldedit.internal.cui.CUIEvent;
@ -67,7 +64,6 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.snapshot.Snapshot;
@ -878,7 +874,7 @@ public class LocalSession implements TextureHolder {
public BlockVector3 getPlacementPosition(Player player) throws IncompleteRegionException {
checkNotNull(player);
if (!placeAtPos1) {
return player.getBlockIn().toVector().toBlockPoint();
return player.getBlockIn().toBlockPoint();
}
return selector.getPrimaryPosition();

View File

@ -150,11 +150,11 @@ public class BiomeCommands extends MethodCommands {
return;
}
BaseBiome biome = player.getWorld().getBiome(blockPosition.toVector().toBlockPoint().toBlockVector2());
BaseBiome biome = player.getWorld().getBiome(blockPosition.toBlockPoint().toBlockVector2());
biomes[biome.getId()]++;
size = 1;
} else if (args.hasFlag('p')) {
BaseBiome biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint().toBlockVector2());
BaseBiome biome = player.getWorld().getBiome(player.getLocation().toBlockPoint().toBlockVector2());
biomes[biome.getId()]++;
size = 1;
} else {
@ -219,7 +219,7 @@ public class BiomeCommands extends MethodCommands {
Mask2D mask2d = mask != null ? mask.toMask2D() : null;
if (atPosition) {
region = new CuboidRegion(player.getLocation().toVector().toBlockPoint(), player.getLocation().toVector().toBlockPoint());
region = new CuboidRegion(player.getLocation().toBlockPoint(), player.getLocation().toBlockPoint());
} else {
region = session.getSelection(world);
}

View File

@ -27,7 +27,7 @@ import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableVector;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.CombinedTransform;
@ -94,11 +94,11 @@ public class FlattenedClipboardTransform {
corners[i] = transformAround.apply(corners[i]);
}
MutableVector newMinimum = new MutableVector(corners[0]);
MutableVector newMaximum = new MutableVector(corners[0]);
// MutableVector cbv = new MutableVector();
MutableVector3 newMinimum = new MutableVector3(corners[0]);
MutableVector3 newMaximum = new MutableVector3(corners[0]);
// MutableVector3 cbv = new MutableVector3();
for (int i = 1; i < corners.length; i++) {
MutableVector cbv = new MutableVector(corners[i]);
MutableVector3 cbv = new MutableVector3(corners[i]);
newMinimum = newMinimum.setComponents(newMinimum.getMinimum(cbv));
newMaximum = newMaximum.setComponents(newMaximum.getMaximum(cbv));
}

View File

@ -31,9 +31,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@ -49,10 +47,8 @@ import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
@ -142,9 +138,9 @@ public class GenerationCommands extends MethodCommands {
image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(), RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
}
// MutableBlockVector pos1 = new MutableBlockVector(player.getLocation().toVector().toBlockPoint());
// MutableBlockVector pos2 = new MutableBlockVector(pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1));
BlockVector3 pos1 = player.getLocation().toVector().toBlockPoint();
// MutableBlockVector3 pos1 = new MutableBlockVector3(player.getLocation().toBlockPoint());
// MutableBlockVector3 pos2 = new MutableBlockVector3(pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1));
BlockVector3 pos1 = player.getLocation().toBlockPoint();
BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
CuboidRegion region = new CuboidRegion(pos1, pos2);
int[] count = new int[1];

View File

@ -40,7 +40,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.command.binding.Range;
@ -167,10 +166,10 @@ public class HistoryCommands extends MethodCommands {
radius = Math.max(Math.min(500, radius), 0);
final World world = player.getWorld();
Location origin = player.getLocation();
BlockVector3 bot = origin.toVector().toBlockPoint().subtract(radius, radius, radius);
BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
bot = bot.withY(Math.max(0, bot.getY()));
// bot.mutY(Math.max(0, bot.getY()));
BlockVector3 top = origin.toVector().toBlockPoint().add(radius, radius, radius);
BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
bot = bot.withY(Math.min(255, top.getY()));
// top.mutY(Math.min(255, top.getY()));
RollbackDatabase database = DBHandler.IMP.getDatabase(world);

View File

@ -190,7 +190,7 @@ public class NavigationCommands {
pos = player.getSolidBlockTrace(300);
}
if (pos != null) {
if(args.hasFlag('f')) player.setPosition(pos.toVector()); else player.findFreePosition(pos);
if(args.hasFlag('f')) player.setPosition(pos); else player.findFreePosition(pos);
BBC.POOF.send(player);
} else {
BBC.NO_BLOCK.send(player);

View File

@ -34,9 +34,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@ -64,7 +62,6 @@ import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
@ -172,7 +169,7 @@ public class RegionCommands extends MethodCommands {
BBC.NO_BLOCK.send(player);
return;
}
CompoundTag nbt = editSession.getFullBlock(pos.toVector().toBlockPoint()).getNbtData();
CompoundTag nbt = editSession.getFullBlock(pos.toBlockPoint()).getNbtData();
if (nbt != null) {
player.print(nbt.getValue().toString());
} else {

View File

@ -35,7 +35,6 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -45,7 +44,6 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.regions.RegionSelector;
@ -65,18 +63,13 @@ import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
@ -115,7 +108,7 @@ public class SelectionCommands {
return;
}
} else {
pos = player.getBlockIn().toVector().toBlockPoint();
pos = player.getBlockIn().toBlockPoint();
}
pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY());
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
@ -148,7 +141,7 @@ public class SelectionCommands {
return;
}
} else {
pos = player.getBlockIn().toVector().toBlockPoint();
pos = player.getBlockIn().toBlockPoint();
}
pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY());
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
@ -169,7 +162,7 @@ public class SelectionCommands {
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos1(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
BlockVector3 pos = player.getBlockTrace(300).toVector().toBlockPoint();
BlockVector3 pos = player.getBlockTrace(300).toBlockPoint();
if (pos != null) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
@ -193,7 +186,7 @@ public class SelectionCommands {
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos2(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
BlockVector3 pos = player.getBlockTrace(300).toVector().toBlockPoint();
BlockVector3 pos = player.getBlockTrace(300).toBlockPoint();
if (pos != null) {
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
@ -254,7 +247,7 @@ public class SelectionCommands {
min2D = (args.hasFlag('c')) ? pos : ChunkStore.toChunk(pos.toBlockVector3());
} else {
// use player loc
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
min2D = ChunkStore.toChunk(player.getBlockIn().toBlockPoint());
}
min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);

View File

@ -6,9 +6,6 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -33,7 +30,7 @@ public class AreaPickaxe implements BlockTool {
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType();
BlockType initialType = clicked.getExtent().getBlock(clicked.toBlockPoint()).getBlockType();
if (initialType.getMaterial().isAir()) {
return true;
@ -63,7 +60,7 @@ public class AreaPickaxe implements BlockTool {
// continue;
// }
//
// ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().toBlockPoint().distanceSq(pos));
// ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toBlockPoint().distanceSq(pos));
//
// editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
// }

View File

@ -37,7 +37,6 @@ import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
/**
* A mode that cycles the data values of supported blocks.
@ -56,8 +55,8 @@ public class BlockDataCyler implements DoubleActionBlockTool {
World world = (World) clicked.getExtent();
// BlockStateHolder block = world.getBlock(clicked.toVector());
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
// BlockStateHolder block = world.getBlock(clicked);
BlockVector3 blockPoint = clicked.toBlockPoint();
BlockState block = world.getBlock(blockPoint);
if (!config.allowedDataCycleBlocks.isEmpty()

View File

@ -19,24 +19,16 @@
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.object.extent.PatternTransform;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
/**
* A mode that replaces one block.
@ -61,7 +53,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
EditSession editSession = session.createEditSession(player);
try {
editSession.setBlock(clicked.toVector().toBlockPoint(), pattern);
editSession.setBlock(clicked.toBlockPoint(), pattern);
} finally {
if (bag != null) {
bag.flushChanges();
@ -76,7 +68,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
EditSession editSession = session.createEditSession(player);
BlockStateHolder targetBlock = (editSession).getBlock(clicked.toVector().toBlockPoint());
BlockStateHolder targetBlock = (editSession).getBlock(clicked.toBlockPoint());
BlockType type = targetBlock.getBlockType();
if (type != null) {

View File

@ -1,7 +1,6 @@
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal;
@ -26,7 +25,6 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
@ -40,7 +38,6 @@ import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import java.io.IOException;
@ -53,7 +50,6 @@ import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Nullable;
import static com.boydti.fawe.object.brush.TargetMode.TARGET_FACE_RANGE;
import static com.google.common.base.Preconditions.checkNotNull;
public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool, ResettableTool, Serializable {
@ -385,7 +381,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
Location loc = player.getLocation();
switch (targetMode) {
case TARGET_BLOCK_RANGE:
return offset(trace(editSession, player, getRange(), true), loc.toVector()).toBlockPoint();
return offset(trace(editSession, player, getRange(), true), loc).toBlockPoint();
case FOWARD_POINT_PITCH: {
int d = 0;
float pitch = loc.getPitch();
@ -393,7 +389,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
d += (int) (Math.sin(Math.toRadians(pitch)) * 50);
final Vector3 vector = loc.getDirection().withY(0).normalize().multiply(d).add(loc.getX(), loc.getY(), loc.getZ());
// vector = vector.add(loc.getX(), loc.getY(), loc.getZ());
return offset(vector, loc.toVector()).toBlockPoint();
return offset(vector, loc).toBlockPoint();
}
case TARGET_POINT_HEIGHT: {
final int height = loc.getBlockY();
@ -407,10 +403,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
}
}
final int distance = (height - y) + 8;
return offset(trace(editSession, player, distance, true), loc.toVector()).toBlockPoint();
return offset(trace(editSession, player, distance, true), loc).toBlockPoint();
}
case TARGET_FACE_RANGE:
return offset(trace(editSession, player, getRange(), true), loc.toVector()).toBlockPoint();
return offset(trace(editSession, player, getRange(), true), loc).toBlockPoint();
default:
return null;
}
@ -429,7 +425,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
@Override
public void run(Vector3 value) {
Location result = tb.getMaskedTargetBlock(useLastBlock);
this.value = result.toVector();
this.value = result;
}
});
}
@ -478,7 +474,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
editSession.setMask(newMask);
//=======
// try {
// brush.build(editSession, target.toVector().toBlockPoint(), material, size);
// brush.build(editSession, target.toBlockPoint(), material, size);
// } catch (MaxChangedBlocksException e) {
// player.printError("Max blocks change limit reached.");
// } finally {

View File

@ -50,7 +50,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = target.toVector().toBlockPoint();
BlockVector3 blockPoint = target.toBlockPoint();
if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(player, session, blockPoint);
}
@ -68,7 +68,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = target.toVector().toBlockPoint();
BlockVector3 blockPoint = target.toBlockPoint();
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(player, session, blockPoint);
}

View File

@ -69,7 +69,7 @@ public class FloatingTreeRemover implements BlockTool {
Player player, LocalSession session, Location clicked) {
final World world = (World) clicked.getExtent();
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
final BlockState state = world.getBlock(clicked.toBlockPoint());
if (!isTreeBlock(state.getBlockType())) {
player.printError("That's not a tree.");
@ -77,7 +77,7 @@ public class FloatingTreeRemover implements BlockTool {
}
final EditSession editSession = session.createEditSession(player);
try /*(EditSession editSession = session.createEditSession(player))*/ {
final Set<BlockVector3> blockSet = bfs(world, clicked.toVector().toBlockPoint());
final Set<BlockVector3> blockSet = bfs(world, clicked.toBlockPoint());
if (blockSet == null) {
player.printError("That's not a floating tree.");
return true;

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
@ -59,7 +58,7 @@ public class FloodFillTool implements BlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
World world = (World) clicked.getExtent();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockVector3 origin = clicked.toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {

View File

@ -58,12 +58,12 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
EditSession eS = session.createEditSession(player);
try {
// eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BlockVector3 blockPoint = pos.toBlockPoint();
BaseBlock applied = secondary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, secondary);
} else {
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), secondary);
}
return true;
} catch (MaxChangedBlocksException e) {
@ -80,12 +80,12 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
try {
// eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BlockVector3 blockPoint = pos.toBlockPoint();
BaseBlock applied = primary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, primary);
} else {
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), primary);
}
return true;
} catch (MaxChangedBlocksException e) {

View File

@ -45,10 +45,10 @@ public class QueryTool implements BlockTool {
World world = (World) clicked.getExtent();
EditSession editSession = session.createEditSession(player);
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
BlockVector3 blockPoint = clicked.toBlockPoint();
BaseBlock block = editSession.getFullBlock(blockPoint);
player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e"
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ block.getBlockType().getName() + "\u00A77" + " ("
+ block.toString() + ") "
+ "\u00A7f"

View File

@ -1,7 +1,5 @@
package com.sk89q.worldedit.command.tool;
import java.util.Set;
import com.boydti.fawe.object.mask.IdMask;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
@ -13,13 +11,6 @@ import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -45,10 +36,10 @@ public class RecursivePickaxe implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
World world = (World) clicked.getExtent();
final BlockVector3 pos = clicked.toVector().toBlockPoint();
final BlockVector3 pos = clicked.toBlockPoint();
EditSession editSession = session.createEditSession(player);
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockVector3 origin = clicked.toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
BlockStateHolder block = editSession.getBlock(pos);
@ -74,8 +65,8 @@ public class RecursivePickaxe implements BlockTool {
session.remember(editSession);
//=======
// try {
// recurse(server, editSession, world, clicked.toVector().toBlockPoint(),
// clicked.toVector().toBlockPoint(), range, initialType, new HashSet<>());
// recurse(server, editSession, world, clicked.toBlockPoint(),
// clicked.toBlockPoint(), range, initialType, new HashSet<>());
// } catch (MaxChangedBlocksException e) {
// player.printError("Max blocks change limit reached.");
// } finally {

View File

@ -44,7 +44,7 @@ public class SinglePickaxe implements BlockTool {
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
World world = (World) clicked.getExtent();
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
BlockVector3 blockPoint = clicked.toBlockPoint();
final BlockType blockType = world.getBlock(blockPoint).getBlockType();
if (blockType == BlockTypes.BEDROCK
&& !player.canDestroyBedrock()) {
@ -61,7 +61,7 @@ public class SinglePickaxe implements BlockTool {
try {
if (editSession.setBlock(clicked.getBlockX(), clicked.getBlockY(), clicked.getBlockZ(), EditSession.nullBlock)) {
// TODO FIXME play effect
// world.playEffect(clicked.toVector(), 2001, blockType);
// world.playEffect(clicked, 2001, blockType);
}
} finally {
editSession.flushQueue();

View File

@ -53,7 +53,7 @@ public class TreePlanter implements BlockTool {
try {
boolean successful = false;
for (int i = 0; i < 10; i++) {
if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0).toBlockPoint())) {
if (treeType.generate(editSession, clicked.add(0, 1, 0).toBlockPoint())) {
successful = true;
break;
}

View File

@ -44,7 +44,7 @@ public class SmoothBrush implements Brush {
Vector3 posDouble = position.toVector3();
Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
Region region = new CuboidRegion(editSession.getWorld(), min.toBlockPoint(), max);
HeightMap heightMap = new HeightMap(editSession, region);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
heightMap.applyFilter(filter, iterations);

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.Player;
@ -36,20 +35,12 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypeUtil;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import java.io.File;
@ -345,12 +336,12 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public Location getBlockIn() {
return getLocation().setPosition(getLocation().toVector().floor());
return getLocation().setPosition(getLocation().floor());
}
@Override
public Location getBlockOn() {
return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).floor());
}
@Override
@ -425,7 +416,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
boolean inFree = false;
while ((block = hitBlox.getNextBlock()) != null) {
boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType().getMaterial().isMovementBlocker();
boolean free = !world.getBlock(block.toBlockPoint()).getBlockType().getMaterial().isMovementBlocker();
if (firstBlock) {
firstBlock = false;

View File

@ -28,7 +28,6 @@ import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.command.tool.*;
import static com.google.common.base.Preconditions.checkNotNull;
@ -44,7 +43,6 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.*;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.HandSide;
@ -310,7 +308,7 @@ public class PlatformManager {
final Actor actor = createProxyActor(event.getCause());
try {
final Location location = event.getLocation();
final BlockVector3 vector = location.toVector().toBlockPoint();
final BlockVector3 vector = location.toBlockPoint();
// At this time, only handle interaction from players
if (actor instanceof Player) {

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import static com.google.common.base.Preconditions.checkNotNull;
@ -112,7 +111,7 @@ public class PlayerProxy extends AbstractPlayerActor {
@Override
public Location getLocation() {
Location loc = this.basePlayer.getLocation();
return new Location(loc.getExtent(), loc.toVector().add(offset), loc.getDirection());
return new Location(loc.getExtent(), loc.add(offset), loc.getDirection());
}
@Override

View File

@ -35,7 +35,7 @@ import com.sk89q.worldedit.function.operation.OperationQueue;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
@ -51,7 +51,7 @@ import javax.annotation.Nullable;
public class AbstractDelegateExtent implements LightingExtent {
private transient final Extent extent;
// private MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
// private MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
/**
* Create a new instance.

View File

@ -39,7 +39,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class MaskingExtent extends AbstractDelegateExtent {
private Mask mask;
// private MutableBlockVector mutable = new MutableBlockVector();
// private MutableBlockVector3 mutable = new MutableBlockVector3();
/**
* Create a new instance.

View File

@ -32,7 +32,6 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BlockState;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -42,9 +41,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
@ -177,7 +175,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
public List<? extends Entity> getEntities(Region region) {
List<Entity> filtered = new ArrayList<>();
for (Entity entity : getEntities()) {
if (region.contains(entity.getLocation().toVector().toBlockPoint())) {
if (region.contains(entity.getLocation().toBlockPoint())) {
filtered.add(entity);
}
}

View File

@ -141,6 +141,8 @@ public class BlockTransformExtent extends ResettableExtent {
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
/**
* Transform the given block using the given transform.
*

View File

@ -26,7 +26,6 @@ import com.sk89q.jnbt.FloatTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
@ -104,7 +103,7 @@ public class ExtentEntityCopy implements EntityFunction {
//<<<<<<< HEAD
// Vector pivot = from.round().add(0.5, 0.5, 0.5);
// Vector newPosition = transform.apply(location.toVector().subtract(pivot));
// Vector newPosition = transform.apply(location.subtract(pivot));
// Vector newDirection;
// if (transform.isIdentity()) {
// newDirection = entity.getLocation().getDirection();
@ -116,7 +115,7 @@ public class ExtentEntityCopy implements EntityFunction {
// }
//=======
Vector3 pivot = from.round().add(0.5, 0.5, 0.5);
Vector3 newPosition = transform.apply(location.toVector().subtract(pivot));
Vector3 newPosition = transform.apply(location.subtract(pivot));
Vector3 newDirection;
newDirection = transform.isIdentity() ?

View File

@ -18,7 +18,7 @@ public class BackwardsExtentBlockCopy implements Operation {
private final RegionFunction function;
private final BlockVector3 origin;
// private Vector mutable = new MutableBlockVector();
// private Vector mutable = new MutableBlockVector3();
public BackwardsExtentBlockCopy(Extent source, Region region, Extent destination, BlockVector3 origin, Transform transform, RegionFunction function) {
this.source = source;

View File

@ -369,7 +369,7 @@ public class ForwardExtentCopy implements Operation {
if (!entities.isEmpty()) {
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
// if (copyingEntities) {
// ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
// ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform);
entityCopy.setRemoving(removingEntities);
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
Operations.completeBlindly(entityVisitor);

View File

@ -29,5 +29,4 @@ public interface FawePattern extends Pattern {
*/
@Override
boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException;
}
}

View File

@ -14,7 +14,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.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
import java.util.ArrayDeque;
@ -217,8 +217,8 @@ public abstract class BreadthFirstSearch implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
MutableBlockVector mutable = new MutableBlockVector();
// MutableBlockVector mutable2 = new MutableBlockVector();
MutableBlockVector3 mutable = new MutableBlockVector3();
// MutableBlockVector3 mutable2 = new MutableBlockVector3();
boolean shouldTrim = false;
IntegerTrio[] dirs = getIntDirections();
BlockVectorSet tempQueue = new BlockVectorSet();

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.function.visitor;
import com.boydti.fawe.object.HasFaweQueue;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;

View File

@ -102,7 +102,7 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
}
if (logMode != null && sender.isPlayer()) {
Vector3 position = player.getLocation().toVector();
Vector3 position = player.getLocation();
LocalSession session = worldEdit.getSessionManager().get(player);
switch (logMode) {

View File

@ -60,22 +60,12 @@ public class BlockVector2 {
}
public static BlockVector2 at(int x, int z) {
switch (x) {
case 0:
if (z == 0) {
return ZERO;
}
break;
case 1:
if (z == 1) {
return ONE;
}
break;
}
return new BlockVector2(x, z);
}
private final int x, z;
protected int x, z;
protected BlockVector2(){}
/**
* Construct an instance.
@ -83,11 +73,31 @@ public class BlockVector2 {
* @param x the X coordinate
* @param z the Z coordinate
*/
private BlockVector2(int x, int z) {
protected BlockVector2(int x, int z) {
this.x = x;
this.z = z;
}
public MutableBlockVector2 setComponents(int x, int z) {
return new MutableBlockVector2(x, z);
}
public MutableBlockVector2 mutX(double x) {
return new MutableBlockVector2((int) x, z);
}
public MutableBlockVector2 mutZ(double z) {
return new MutableBlockVector2(x, (int) z);
}
public MutableBlockVector2 mutX(int x) {
return new MutableBlockVector2(x, z);
}
public MutableBlockVector2 mutZ(int z) {
return new MutableBlockVector2(x, z);
}
/**
* Get the X coordinate.
*
@ -144,6 +154,35 @@ public class BlockVector2 {
return BlockVector2.at(x, z);
}
public MutableBlockVector2 nextPosition() {
int absX = Math.abs(x);
int absY = Math.abs(z);
if (absX > absY) {
if (x > 0) {
return setComponents(x, z + 1);
} else {
return setComponents(x, z - 1);
}
} else if (absY > absX) {
if (z > 0) {
return setComponents(x - 1, z);
} else {
return setComponents(x + 1, z);
}
} else {
if (x == z && x > 0) {
return setComponents(x, z + 1);
}
if (x == absX) {
return setComponents(x, z + 1);
}
if (z == absY) {
return setComponents(x, z - 1);
}
return setComponents(x + 1, z);
}
}
/**
* Add another vector to this vector and return the result as a new vector.
*

View File

@ -42,20 +42,6 @@ public class BlockVector3 {
}
public static BlockVector3 at(int x, int y, int z) {
// switch for efficiency on typical cases
// in MC y is rarely 0/1 on selections
switch (y) {
case 0:
if (x == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && z == 1) {
return ONE;
}
break;
}
return new BlockVector3(x, y, z);
}
@ -80,7 +66,9 @@ public class BlockVector3 {
return YzxOrderComparator.YZX_ORDER;
}
private final int x, y, z;
protected int x, y, z;
protected BlockVector3(){}
/**
* Construct an instance.
@ -89,12 +77,44 @@ public class BlockVector3 {
* @param y the Y coordinate
* @param z the Z coordinate
*/
private BlockVector3(int x, int y, int z) {
protected BlockVector3(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public MutableBlockVector3 setComponents(double x, double y, double z) {
return new MutableBlockVector3((int) x, (int) y, (int) z);
}
public MutableBlockVector3 setComponents(int x, int y, int z) {
return new MutableBlockVector3(x, y, z);
}
public MutableBlockVector3 mutX(double x) {
return new MutableBlockVector3((int) x, y, z);
}
public MutableBlockVector3 mutY(double y) {
return new MutableBlockVector3(x, (int) y, z);
}
public MutableBlockVector3 mutZ(double z) {
return new MutableBlockVector3(x, y, (int) z);
}
public MutableBlockVector3 mutX(int x) {
return new MutableBlockVector3(x, y, z);
}
public MutableBlockVector3 mutY(int y) {
return new MutableBlockVector3(x, y, z);
}
public MutableBlockVector3 mutZ(int z) {
return new MutableBlockVector3(x, y, z);
}
/**
* Get the X coordinate.
*

View File

@ -1,629 +0,0 @@
package com.sk89q.worldedit.math;
import com.boydti.fawe.util.MathMan;
import com.google.common.collect.ComparisonChain;
import com.sk89q.worldedit.math.transform.AffineTransform;
import static com.google.common.base.Preconditions.checkArgument;
import java.io.IOException;
import java.io.Serializable;
import java.util.Comparator;
/**
* A mutable rendition of WorldEdit's BlockVector3 class.
* This class should ONLY be used locally for efficient vector manipulation.
*/
public class MutableBlockVector implements Serializable {
private transient int x, y, z;
private static ThreadLocal<MutableBlockVector> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector>() {
@Override
protected MutableBlockVector initialValue() {
return new MutableBlockVector();
}
};
public static MutableBlockVector get(int x, int y, int z) {
return MUTABLE_CACHE.get().setComponents(x, y, z);
}
public MutableBlockVector(BlockVector3 v) {
this(v.getBlockX(), v.getBlockY(), v.getBlockZ());
}
public MutableBlockVector(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public MutableBlockVector() {
this(0, 0, 0);
}
public static final MutableBlockVector ZERO = new MutableBlockVector(0, 0, 0);
public static final MutableBlockVector UNIT_X = new MutableBlockVector(1, 0, 0);
public static final MutableBlockVector UNIT_Y = new MutableBlockVector(0, 1, 0);
public static final MutableBlockVector UNIT_Z = new MutableBlockVector(0, 0, 1);
public static final MutableBlockVector ONE = new MutableBlockVector(1, 1, 1);
// thread-safe initialization idiom
private static final class YzxOrderComparator {
private static final Comparator<MutableBlockVector> YZX_ORDER = (a, b) -> {
return ComparisonChain.start()
.compare(a.y, b.y)
.compare(a.z, b.z)
.compare(a.x, b.x)
.result();
};
}
/**
* Returns a comparator that sorts vectors first by Y, then Z, then X.
*
* <p>
* Useful for sorting by chunk block storage order.
*/
public static Comparator<MutableBlockVector> sortByCoordsYzx() {
return YzxOrderComparator.YZX_ORDER;
}
public MutableBlockVector setComponents(BlockVector3 other) {
return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ());
}
public MutableBlockVector setComponents(double x, double y, double z) {
return this.setComponents((int) x, (int) y, (int) z);
}
public MutableBlockVector setComponents(int x, int y, int z) {
this.mutX(x);
this.mutY(y);
this.mutZ(z);
return this;
}
public final void mutX(double x) {
this.x = MathMan.roundInt(x);
}
public final void mutY(double y) {
this.y = MathMan.roundInt(y);
}
public final void mutZ(double z) {
this.z = MathMan.roundInt(z);
}
public final void mutX(int x) {
this.x = x;
}
public final void mutY(int y) {
this.y = y;
}
public final void mutZ(int z) {
this.z = z;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public int getX() {
return x;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public int getBlockX() {
return x;
}
/**
* Get the Y coordinate.
*
* @return the y coordinate
*/
public int getY() {
return y;
}
/**
* Get the Y coordinate.
*
* @return the y coordinate
*/
public int getBlockY() {
return y;
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public int getZ() {
return z;
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public int getBlockZ() {
return z;
}
/**
* Add another vector to this vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector add(MutableBlockVector other) {
return add(other.x, other.y, other.z);
}
/**
* Add another vector to this vector.
*
* @param x the value to add
* @param y the value to add
* @param z the value to add
* @return a new vector
*/
public MutableBlockVector add(int x, int y, int z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
/**
* Add a list of vectors to this vector and return the
* result as a new vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector add(MutableBlockVector... others) {
for (MutableBlockVector other : others) {
x += other.x;
y += other.y;
z += other.z;
}
return this;
}
/**
* Subtract another vector from this vector and return the result
* as a new vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector subtract(MutableBlockVector other) {
return subtract(other.x, other.y, other.z);
}
/**
* Subtract another vector from this vector and return the result
* as a new vector.
*
* @param x the value to subtract
* @param y the value to subtract
* @param z the value to subtract
* @return a new vector
*/
public MutableBlockVector subtract(int x, int y, int z) {
this.x -= x;
this.y -= y;
this.z -= z;
return this;
}
/**
* Subtract a list of vectors from this vector and return the result
* as a new vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector subtract(MutableBlockVector... others) {
for (MutableBlockVector other : others) {
x -= other.x;
y -= other.y;
z -= other.z;
}
return this;
}
/**
* Multiply this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector multiply(MutableBlockVector other) {
return multiply(other.x, other.y, other.z);
}
/**
* Multiply this vector by another vector on each component.
*
* @param x the value to multiply
* @param y the value to multiply
* @param z the value to multiply
* @return a new vector
*/
public MutableBlockVector multiply(int x, int y, int z) {
this.x *= x;
this.y *= y;
this.z *= z;
return this;
}
/**
* Multiply this vector by zero or more vectors on each component.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector multiply(MutableBlockVector... others) {
for (MutableBlockVector other : others) {
x *= other.x;
y *= other.y;
z *= other.z;
}
return this;
}
/**
* Perform scalar multiplication and return a new vector.
*
* @param n the value to multiply
* @return a new vector
*/
public MutableBlockVector multiply(int n) {
return multiply(n, n, n);
}
/**
* Divide this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector divide(MutableBlockVector other) {
return divide(other.x, other.y, other.z);
}
/**
* Divide this vector by another vector on each component.
*
* @param x the value to divide by
* @param y the value to divide by
* @param z the value to divide by
* @return a new vector
*/
public MutableBlockVector divide(int x, int y, int z) {
this.x /= x;
this.y /= y;
this.z /= z;
return this;
}
/**
* Perform scalar division and return a new vector.
*
* @param n the value to divide by
* @return a new vector
*/
public MutableBlockVector divide(int n) {
return divide(n, n, n);
}
/**
* Get the length of the vector.
*
* @return length
*/
public double length() {
return Math.sqrt(lengthSq());
}
/**
* Get the length, squared, of the vector.
*
* @return length, squared
*/
public int lengthSq() {
return x * x + y * y + z * z;
}
/**
* Get the distance between this vector and another vector.
*
* @param other the other vector
* @return distance
*/
public double distance(MutableBlockVector other) {
return Math.sqrt(distanceSq(other));
}
/**
* Get the distance between this vector and another vector, squared.
*
* @param other the other vector
* @return distance
*/
public int distanceSq(MutableBlockVector other) {
int dx = other.x - x;
int dy = other.y - y;
int dz = other.z - z;
return dx * dx + dy * dy + dz * dz;
}
/**
* Get the normalized vector, which is the vector divided by its
* length, as a new vector.
*
* @return a new vector
*/
public MutableBlockVector normalize() {
double len = length();
x /= len;
y /= len;
z /= len;
return this;
}
/**
* Gets the dot product of this and another vector.
*
* @param other the other vector
* @return the dot product of this and the other vector
*/
public double dot(MutableBlockVector other) {
return x * other.x + y * other.y + z * other.z;
}
/**
* Gets the cross product of this and another vector.
*
* @param other the other vector
* @return the cross product of this and the other vector
*/
public MutableBlockVector cross(MutableBlockVector other) {
x = y * other.z - z * other.y;
y = z * other.x - x * other.z;
z = x * other.y - y * other.x;
return this;
}
/**
* Checks to see if a vector is contained with another.
*
* @param min the minimum point (X, Y, and Z are the lowest)
* @param max the maximum point (X, Y, and Z are the lowest)
* @return true if the vector is contained
*/
public boolean containedWithin(MutableBlockVector min, MutableBlockVector max) {
return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
}
/**
* Clamp the Y component.
*
* @param min the minimum value
* @param max the maximum value
* @return a new vector
*/
public MutableBlockVector clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum");
if (y < min) {
y = min;
}
if (y > max) {
y = max;
}
return this;
}
/**
* Floors the values of all components.
*
* @return a new vector
*/
public MutableBlockVector floor() {
// already floored, kept for feature parity with Vector3
return this;
}
/**
* Rounds all components up.
*
* @return a new vector
*/
public MutableBlockVector ceil() {
// already raised, kept for feature parity with Vector3
return this;
}
/**
* Rounds all components to the closest integer.
*
* <p>Components &lt; 0.5 are rounded down, otherwise up.</p>
*
* @return a new vector
*/
public MutableBlockVector round() {
// already rounded, kept for feature parity with Vector3
return this;
}
/**
* Returns a vector with the absolute values of the components of
* this vector.
*
* @return a new vector
*/
public MutableBlockVector abs() {
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
return this;
}
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
* @see AffineTransform another method to transform vectors
*/
public MutableBlockVector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle);
double x = this.x - aboutX;
double z = this.z - aboutZ;
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x2 = x * cos - z * sin;
double z2 = x * sin + z * cos;
this.x = (int) Math.floor(x2 + aboutX + translateX);
this.z = (int) Math.floor(z2 + aboutZ + translateZ);
return this;
}
/**
* Get this vector's pitch as used within the game.
*
* @return pitch in radians
*/
public double toPitch() {
double x = getX();
double z = getZ();
if (x == 0 && z == 0) {
return getY() > 0 ? -90 : 90;
} else {
double x2 = x * x;
double z2 = z * z;
double xz = Math.sqrt(x2 + z2);
return Math.toDegrees(Math.atan(-getY() / xz));
}
}
/**
* Get this vector's yaw as used within the game.
*
* @return yaw in radians
*/
public double toYaw() {
double x = getX();
double z = getZ();
double t = Math.atan2(-x, z);
double tau = 2 * Math.PI;
return Math.toDegrees(((t + tau) % tau));
}
/**
* Gets the minimum components of two vectors.
*
* @param v2 the second vector
* @return minimum
*/
public MutableBlockVector getMinimum(MutableBlockVector v2) {
x = Math.min(x, v2.x);
y = Math.min(y, v2.y);
z = Math.min(z, v2.z);
return this;
}
/**
* Gets the maximum components of two vectors.
*
* @param v2 the second vector
* @return maximum
*/
public MutableBlockVector getMaximum(MutableBlockVector v2) {
x = Math.max(x, v2.x);
y = Math.max(y, v2.y);
z = Math.max(z, v2.z);
return this;
}
/**
* Creates a 2D vector by dropping the Y component from this vector.
*
* @return a new {@link BlockVector2}
*/
public BlockVector2 toBlockVector2() {
return BlockVector2.at(x, z);
}
public Vector3 toVector3() {
return Vector3.at(x, y, z);
}
public BlockVector3 toBlockVector3() {
return BlockVector3.at(x, y, z);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MutableBlockVector)) {
return false;
}
MutableBlockVector other = (MutableBlockVector) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Integer.hashCode(x);
hash = 31 * hash + Integer.hashCode(y);
hash = 31 * hash + Integer.hashCode(z);
return hash;
}
@Override
public String toString() {
return "Mutable (" + x + ", " + y + ", " + z + ")";
}
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
stream.writeInt(x);
stream.writeByte((byte) y);
stream.writeInt(z);
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
this.x = stream.readInt();
this.y = stream.readByte() & 0xFF;
this.z = stream.readInt();
}
}

View File

@ -0,0 +1,52 @@
package com.sk89q.worldedit.math;
public class MutableBlockVector2 extends BlockVector2 {
private static ThreadLocal<MutableBlockVector2> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector2>() {
@Override
protected MutableBlockVector2 initialValue() {
return new MutableBlockVector2();
}
};
public static MutableBlockVector2 get(int x, int z) {
return MUTABLE_CACHE.get().setComponents(x, z);
}
public MutableBlockVector2() {}
public MutableBlockVector2(int x, int z) {
super(x, z);
}
@Override
public MutableBlockVector2 setComponents(int x, int z) {
this.x = x;
this.z = z;
return this;
}
@Override
public MutableBlockVector2 mutX(double x) {
this.x = (int) x;
return this;
}
@Override
public MutableBlockVector2 mutZ(double z) {
this.z = (int) z;
return this;
}
@Override
public MutableBlockVector2 mutX(int x) {
this.x = x;
return this;
}
@Override
public MutableBlockVector2 mutZ(int z) {
this.z = z;
return this;
}
}

View File

@ -1,594 +0,0 @@
package com.sk89q.worldedit.math;
import java.io.IOException;
import java.io.Serializable;
import java.util.Comparator;
import com.google.common.collect.ComparisonChain;
import com.sk89q.worldedit.math.transform.AffineTransform;
/**
* A mutable rendition of WorldEdit's BlockVector2 class.
* This class should ONLY be used locally for efficient vector manipulation.
*/
public final class MutableBlockVector2D implements Serializable {
private static ThreadLocal<MutableBlockVector2D> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector2D>() {
@Override
protected MutableBlockVector2D initialValue() {
return new MutableBlockVector2D();
}
};
public static MutableBlockVector2D get(int x, int z) {
return MUTABLE_CACHE.get().setComponents(x, z);
}
private transient int x, z;
public MutableBlockVector2D() {
this(0, 0);
}
public static final MutableBlockVector2D ZERO = new MutableBlockVector2D(0, 0);
public static final MutableBlockVector2D UNIT_X = new MutableBlockVector2D(1, 0);
public static final MutableBlockVector2D UNIT_Z = new MutableBlockVector2D(0, 1);
public static final MutableBlockVector2D ONE = new MutableBlockVector2D(1, 1);
/**
* A comparator for MutableBlockVector2Ds that orders the vectors by rows, with x as the
* column and z as the row.
*
* For example, if x is the horizontal axis and z is the vertical axis, it
* sorts like so:
*
* <pre>
* 0123
* 4567
* 90ab
* cdef
* </pre>
*/
public static final Comparator<MutableBlockVector2D> COMPARING_GRID_ARRANGEMENT = (a, b) -> {
return ComparisonChain.start()
.compare(a.getBlockZ(), b.getBlockZ())
.compare(a.getBlockX(), b.getBlockX())
.result();
};
/**
* Construct an instance.
*
* @param vector
*/
public MutableBlockVector2D(BlockVector2 vector) {
this(vector.getBlockX(), vector.getBlockZ());
}
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
public MutableBlockVector2D(double x, double z) {
this((int) Math.floor(x), (int) Math.floor(z));
}
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
public MutableBlockVector2D(int x, int z) {
this.x = x;
this.z = z;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public int getX() {
return x;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public int getBlockX() {
return x;
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public int getZ() {
return z;
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public int getBlockZ() {
return z;
}
/**
* Add another vector to this vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector2D add(MutableBlockVector2D other) {
return add(other.x, other.z);
}
/**
* Add another vector to this vector.
*
* @param x the value to add
* @param z the value to add
* @return a new vector
*/
public MutableBlockVector2D add(int x, int z) {
this.x += x;
this.z += z;
return this;
}
/**
* Add a list of vectors to this vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector2D add(MutableBlockVector2D... others) {
for (MutableBlockVector2D other : others) {
x += other.x;
x += other.z;
}
return this;
}
/**
* Subtract another vector from this vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector2D subtract(MutableBlockVector2D other) {
return subtract(other.x, other.z);
}
/**
* Subtract another vector from this vector.
*
* @param x the value to subtract
* @param z the value to subtract
* @return a new vector
*/
public MutableBlockVector2D subtract(int x, int z) {
this.x -= x;
this.z -= z;
return this;
}
/**
* Subtract a list of vectors from this vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector2D subtract(MutableBlockVector2D... others) {
for (MutableBlockVector2D other : others) {
x -= other.x;
z -= other.z;
}
return this;
}
/**
* Multiply this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector2D multiply(MutableBlockVector2D other) {
return multiply(other.x, other.z);
}
/**
* Multiply this vector by another vector on each component.
*
* @param x the value to multiply
* @param z the value to multiply
* @return a new vector
*/
public MutableBlockVector2D multiply(int x, int z) {
this.x *= x;
this.z *= z;
return this;
}
/**
* Multiply this vector by zero or more vectors on each component.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableBlockVector2D multiply(MutableBlockVector2D... others) {
for (MutableBlockVector2D other : others) {
x *= other.x;
z *= other.z;
}
return this;
}
/**
* Perform scalar multiplication.
*
* @param n the value to multiply
* @return a new vector
*/
public MutableBlockVector2D multiply(int n) {
return multiply(n, n);
}
/**
* Divide this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableBlockVector2D divide(MutableBlockVector2D other) {
return divide(other.x, other.z);
}
/**
* Divide this vector by another vector on each component.
*
* @param x the value to divide by
* @param z the value to divide by
* @return a new vector
*/
public MutableBlockVector2D divide(int x, int z) {
this.x /= x;
this.z /= z;
return this;
}
/**
* Perform scalar division.
*
* @param n the value to divide by
* @return a new vector
*/
public MutableBlockVector2D divide(int n) {
return divide(n, n);
}
/**
* Get the length of the vector.
*
* @return length
*/
public double length() {
return Math.sqrt(lengthSq());
}
/**
* Get the length, squared, of the vector.
*
* @return length, squared
*/
public int lengthSq() {
return x * x + z * z;
}
/**
* Get the distance between this vector and another vector.
*
* @param other the other vector
* @return distance
*/
public double distance(MutableBlockVector2D other) {
return Math.sqrt(distanceSq(other));
}
/**
* Get the distance between this vector and another vector, squared.
*
* @param other the other vector
* @return distance
*/
public int distanceSq(MutableBlockVector2D other) {
int dx = other.x - x;
int dz = other.z - z;
return dx * dx + dz * dz;
}
/**
* Get the normalized vector, which is the vector divided by its
* length.
*
* @return a new vector
*/
public MutableBlockVector2D normalize() {
double len = length();
this.x /= len;
this.z /= len;
return this;
}
/**
* Gets the dot product of this and another vector.
*
* @param other the other vector
* @return the dot product of this and the other vector
*/
public int dot(MutableBlockVector2D other) {
return x * other.x + z * other.z;
}
/**
* Checks to see if a vector is contained with another.
*
* @param min the minimum point (X, Y, and Z are the lowest)
* @param max the maximum point (X, Y, and Z are the lowest)
* @return true if the vector is contained
*/
public boolean containedWithin(MutableBlockVector2D min, MutableBlockVector2D max) {
return x >= min.x && x <= max.x
&& z >= min.z && z <= max.z;
}
/**
* Floors the values of all components.
*
* @return a new vector
*/
public MutableBlockVector2D floor() {
// already floored, kept for feature parity with Vector2
return this;
}
/**
* Rounds all components up.
*
* @return a new vector
*/
public MutableBlockVector2D ceil() {
// already raised, kept for feature parity with Vector2
return this;
}
/**
* Rounds all components to the closest integer.
*
* <p>Components &lt; 0.5 are rounded down, otherwise up.</p>
*
* @return a new vector
*/
public MutableBlockVector2D round() {
// already rounded, kept for feature parity with Vector2
return this;
}
/**
* Returns a vector with the absolute values of the components of
* this vector.
*
* @return a new vector
*/
public MutableBlockVector2D abs() {
x = Math.abs(x);
z = Math.abs(z);
return this;
}
/**
* Perform a 2D transformation on this vector.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
* @see AffineTransform another method to transform vectors
*/
public MutableBlockVector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle);
double x = this.x - aboutX;
double z = this.z - aboutZ;
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x2 = x * cos - z * sin;
double z2 = x * sin + z * cos;
this.x = (int) Math.floor(x2 + aboutX + translateX);
this.z = (int) Math.floor(z2 + aboutZ + translateZ);
return this;
}
/**
* Gets the minimum components of two vectors.
*
* @param v2 the second vector
* @return minimum
*/
public MutableBlockVector2D getMinimum(MutableBlockVector2D v2) {
x = Math.min(x, v2.x);
z = Math.min(z, v2.z);
return this;
}
/**
* Gets the maximum components of two vectors.
*
* @param v2 the second vector
* @return maximum
*/
public MutableBlockVector2D getMaximum(MutableBlockVector2D v2) {
x = Math.max(x, v2.x);
z = Math.max(z, v2.z);
return this;
}
/**
* Creates a 2D vector from this vector.
*
* @return a new vector
*/
public Vector2 toVector2() {
return Vector2.at(x, z);
}
/**
* Creates a 3D vector by adding a zero Y component to this vector.
*
* @return a new vector
*/
public Vector3 toVector3() {
return toVector3(0);
}
/**
* Creates a 3D vector by adding the specified Y component to this vector.
*
* @param y the Y component
* @return a new vector
*/
public Vector3 toVector3(double y) {
return Vector3.at(x, y, z);
}
/**
* Creates a 3D vector by adding a zero Y component to this vector.
*
* @return a new vector
*/
public BlockVector3 toBlockVector3() {
return toBlockVector3(0);
}
/**
* Creates a 3D vector by adding the specified Y component to this vector.
*
* @param y the Y component
* @return a new vector
*/
public BlockVector3 toBlockVector3(int y) {
return BlockVector3.at(x, y, z);
}
/**
* Creates a 2D vector from this vector.
*
* @return a new vector
*/
public BlockVector2 toBlockVector2() {
return BlockVector2.at(x, z);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MutableBlockVector2D)) {
return false;
}
MutableBlockVector2D other = (MutableBlockVector2D) obj;
return other.x == this.x && other.z == this.z;
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Integer.hashCode(x);
hash = 31 * hash + Integer.hashCode(z);
return hash;
}
@Override
public String toString() {
return "Mutable (" + x + ", " + z + ")";
}
public MutableBlockVector2D setComponents(int x, int z) {
this.x = x;
this.z = z;
return this;
}
public MutableBlockVector2D setComponents(double x, double z) {
return setComponents((int) x, (int) z);
}
public final void mutX(int x) {
this.x = x;
}
public void mutZ(int z) {
this.z = z;
}
public final void mutX(double x) {
this.x = (int) x;
}
public void mutZ(double z) {
this.z = (int) z;
}
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
stream.writeInt(x);
stream.writeInt(z);
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
this.x = stream.readInt();
this.z = stream.readInt();
}
public MutableBlockVector2D nextPosition() {
int absX = Math.abs(x);
int absY = Math.abs(z);
if (absX > absY) {
if (x > 0) {
return setComponents(x, z + 1);
} else {
return setComponents(x, z - 1);
}
} else if (absY > absX) {
if (z > 0) {
return setComponents(x - 1, z);
} else {
return setComponents(x + 1, z);
}
} else {
if (x == z && x > 0) {
return setComponents(x, z + 1);
}
if (x == absX) {
return setComponents(x, z + 1);
}
if (z == absY) {
return setComponents(x, z - 1);
}
return setComponents(x + 1, z);
}
}
}

View File

@ -0,0 +1,73 @@
package com.sk89q.worldedit.math;
public class MutableBlockVector3 extends BlockVector3 {
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector3>() {
@Override
protected MutableBlockVector3 initialValue() {
return new MutableBlockVector3();
}
};
public static MutableBlockVector3 get(int x, int y, int z) {
return MUTABLE_CACHE.get().setComponents(x, y, z);
}
public MutableBlockVector3() {}
public MutableBlockVector3(BlockVector3 other) {
super(other.getX(), other.getY(), other.getZ());
}
public MutableBlockVector3 setComponents(BlockVector3 other) {
return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ());
}
public MutableBlockVector3(int x, int y, int z) {
super(x, y, z);
}
@Override
public MutableBlockVector3 setComponents(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public MutableBlockVector3 mutX(double x) {
this.x = (int) x;
return this;
}
@Override
public MutableBlockVector3 mutY(double y) {
this.y = (int) y;
return this;
}
@Override
public MutableBlockVector3 mutZ(double z) {
this.z = (int) z;
return this;
}
@Override
public final MutableBlockVector3 mutX(int x) {
this.x = x;
return this;
}
@Override
public final MutableBlockVector3 mutY(int y) {
this.y = y;
return this;
}
@Override
public final MutableBlockVector3 mutZ(int z) {
this.z = z;
return this;
}
}

View File

@ -1,581 +0,0 @@
package com.sk89q.worldedit.math;
import com.sk89q.worldedit.math.transform.AffineTransform;
import static com.google.common.base.Preconditions.checkArgument;
import java.io.IOException;
import java.io.Serializable;
/**
* A mutable rendition of WorldEdit's Vector3 class.
* This class should ONLY be used locally for efficient vector manipulation.
*/
public class MutableVector implements Serializable {
private transient double x, y, z;
private static ThreadLocal<MutableVector> MUTABLE_CACHE = new ThreadLocal<MutableVector>() {
@Override
protected MutableVector initialValue() {
return new MutableVector();
}
};
public static MutableVector get(double x, double y, double z) {
return MUTABLE_CACHE.get().setComponents(x, y, z);
}
public MutableVector(Vector3 v) {
this(v.getX(), v.getY(), v.getZ());
}
public MutableVector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public MutableVector() {
this(0, 0, 0);
}
public MutableVector setComponents(Vector3 other) {
return setComponents(other.getX(), other.getY(), other.getZ());
}
public MutableVector setComponents(MutableVector mutable) {
return setComponents(mutable.getX(), mutable.getY(), mutable.getZ());
}
public MutableVector setComponents(int x, int y, int z) {
return this.setComponents((double) x, (double) y, (double) z);
}
public MutableVector setComponents(double x, double y, double z) {
this.mutX(x);
this.mutY(y);
this.mutZ(z);
return this;
}
public final void mutX(double x) {
this.x = y;
}
public final void mutY(double y) {
this.y = y;
}
public final void mutZ(double z) {
this.z = y;
}
public final void mutX(int x) {
this.x = (double)x;
}
public final void mutY(int y) {
this.y = (double)y;
}
public final void mutZ(int z) {
this.z = (double)z;
}
public final double getX() {
return x;
}
public final double getY() {
return y;
}
public final double getZ() {
return z;
}
/**
* Add another vector to this vector and return the result as a new vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableVector add(MutableVector other) {
return add(other.x, other.y, other.z);
}
/**
* Add another vector to this vector and return the result as a new vector.
*
* @param x the value to add
* @param y the value to add
* @param z the value to add
* @return a new vector
*/
public MutableVector add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
/**
* Add a list of vectors to this vector and return the
* result as a new vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableVector add(MutableVector... others) {
for (MutableVector other : others) {
x += other.x;
y += other.y;
z += other.z;
}
return this;
}
/**
* Subtract another vector from this vector and return the result
* as a new vector.
*
* @param other the other vector
* @return a new vector
*/
public MutableVector subtract(MutableVector other) {
return subtract(other.x, other.y, other.z);
}
/**
* Subtract another vector from this vector and return the result
* as a new vector.
*
* @param x the value to subtract
* @param y the value to subtract
* @param z the value to subtract
* @return a new vector
*/
public MutableVector subtract(double x, double y, double z) {
this.x -= x;
this.y -= y;
this.z -= z;
return this;
}
/**
* Subtract a list of vectors from this vector and return the result
* as a new vector.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableVector subtract(MutableVector... others) {
for (MutableVector other : others) {
x -= other.x;
y -= other.y;
z -= other.z;
}
return this;
}
/**
* Multiply this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableVector multiply(MutableVector other) {
return multiply(other.x, other.y, other.z);
}
/**
* Multiply this vector by another vector on each component.
*
* @param x the value to multiply
* @param y the value to multiply
* @param z the value to multiply
* @return a new vector
*/
public MutableVector multiply(double x, double y, double z) {
this.x *= x;
this.y *= y;
this.z *= z;
return this;
}
/**
* Multiply this vector by zero or more vectors on each component.
*
* @param others an array of vectors
* @return a new vector
*/
public MutableVector multiply(MutableVector... others) {
for (MutableVector other : others) {
x *= other.x;
y *= other.y;
z *= other.z;
}
return this;
}
/**
* Perform scalar multiplication and return a new vector.
*
* @param n the value to multiply
* @return a new vector
*/
public MutableVector multiply(double n) {
return multiply(n, n, n);
}
/**
* Divide this vector by another vector on each component.
*
* @param other the other vector
* @return a new vector
*/
public MutableVector divide(MutableVector other) {
return divide(other.x, other.y, other.z);
}
/**
* Divide this vector by another vector on each component.
*
* @param x the value to divide by
* @param y the value to divide by
* @param z the value to divide by
* @return a new vector
*/
public MutableVector divide(double x, double y, double z) {
this.x /= x;
this.y /= y;
this.z /= z;
return this;
}
/**
* Perform scalar division and return a new vector.
*
* @param n the value to divide by
* @return a new vector
*/
public MutableVector divide(double n) {
return divide(n, n, n);
}
/**
* Get the length of the vector.
*
* @return length
*/
public double length() {
return Math.sqrt(lengthSq());
}
/**
* Get the length, squared, of the vector.
*
* @return length, squared
*/
public double lengthSq() {
return x * x + y * y + z * z;
}
/**
* Get the distance between this vector and another vector.
*
* @param other the other vector
* @return distance
*/
public double distance(Vector3 other) {
return Math.sqrt(distanceSq(other));
}
/**
* Get the distance between this vector and another vector, squared.
*
* @param other the other vector
* @return distance
*/
public double distanceSq(Vector3 other) {
double dx = other.getX() - x;
double dy = other.getY() - y;
double dz = other.getZ() - z;
return dx * dx + dy * dy + dz * dz;
}
/**
* Get the normalized vector, which is the vector divided by its
* length, as a new vector.
*
* @return a new vector
*/
public MutableVector normalize() {
return divide(length());
}
/**
* Gets the dot product of this and another vector.
*
* @param other the other vector
* @return the dot product of this and the other vector
*/
public double dot(MutableVector other) {
return x * other.x + y * other.y + z * other.z;
}
/**
* Gets the cross product of this and another vector.
*
* @param other the other vector
* @return the cross product of this and the other vector
*/
public Vector3 cross(MutableVector other) {
return Vector3.at(
y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x
);
}
/**
* Checks to see if a vector is contained with another.
*
* @param min the minimum point (X, Y, and Z are the lowest)
* @param max the maximum point (X, Y, and Z are the lowest)
* @return true if the vector is contained
*/
public boolean containedWithin(MutableVector min, MutableVector max) {
return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
}
/**
* Clamp the Y component.
*
* @param min the minimum value
* @param max the maximum value
* @return a new vector
*/
public MutableVector clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum");
if (y < min) {
y = min;
}
if (y > max) {
y = max;
}
return this;
}
/**
* Floors the values of all components.
*
* @return a new vector
*/
public MutableVector floor() {
x = Math.floor(x);
y = Math.floor(y);
z = Math.floor(z);
return this;
}
/**
* Rounds all components up.
*
* @return a new vector
*/
public MutableVector ceil() {
x = Math.ceil(x);
y = Math.ceil(y);
z = Math.ceil(z);
return this;
}
/**
* Rounds all components to the closest integer.
*
* <p>Components &lt; 0.5 are rounded down, otherwise up.</p>
*
* @return a new vector
*/
public MutableVector round() {
x = Math.floor(x + 0.5);
y = Math.floor(y + 0.5);
z = Math.floor(z + 0.5);
return this;
}
/**
* Returns a vector with the absolute values of the components of
* this vector.
*
* @return a new vector
*/
public MutableVector abs() {
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
return this;
}
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
* @see AffineTransform another method to transform vectors
*/
public MutableVector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle);
double x = this.x - aboutX;
double z = this.z - aboutZ;
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x2 = x * cos - z * sin;
double z2 = x * sin + z * cos;
this.x = x2 + aboutX + translateX;
this.z = z2 + aboutZ + translateZ;
return this;
}
/**
* Get this vector's pitch as used within the game.
*
* @return pitch in radians
*/
public double toPitch() {
double x = getX();
double z = getZ();
if (x == 0 && z == 0) {
return getY() > 0 ? -90 : 90;
} else {
double x2 = x * x;
double z2 = z * z;
double xz = Math.sqrt(x2 + z2);
return Math.toDegrees(Math.atan(-getY() / xz));
}
}
/**
* Get this vector's yaw as used within the game.
*
* @return yaw in radians
*/
public double toYaw() {
double x = getX();
double z = getZ();
double t = Math.atan2(-x, z);
double tau = 2 * Math.PI;
return Math.toDegrees(((t + tau) % tau));
}
/**
* Gets the minimum components of two vectors.
*
* @param v2 the second vector
* @return minimum
*/
public MutableVector getMinimum(MutableVector v2) {
x = Math.min(x, v2.x);
y = Math.min(y, v2.y);
z = Math.min(z, v2.z);
return this;
}
/**
* Gets the maximum components of two vectors.
*
* @param v2 the second vector
* @return maximum
*/
public MutableVector getMaximum(MutableVector v2) {
x = Math.max(x, v2.x);
y = Math.max(y, v2.y);
z = Math.max(z, v2.z);
return this;
}
/**
* Create a new {@code BlockVector} using the given components.
*
* @param x the X coordinate
* @param y the Y coordinate
* @param z the Z coordinate
* @return a new {@code BlockVector}
*/
public static BlockVector3 toBlockPoint(double x, double y, double z) {
return BlockVector3.at(x, y, z);
}
/**
* Create a new {@code BlockVector} from this vector.
*
* @return a new {@code BlockVector}
*/
public BlockVector3 toBlockPoint() {
return toBlockPoint(x, y, z);
}
/**
* Creates a 2D vector by dropping the Y component from this vector.
*
* @return a new {@link Vector2}
*/
public Vector2 toVector2() {
return Vector2.at(x, z);
}
public Vector3 toVector3() {
return Vector3.at(x, y, z);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MutableVector)) {
return false;
}
MutableVector other = (MutableVector) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Double.hashCode(x);
hash = 31 * hash + Double.hashCode(y);
hash = 31 * hash + Double.hashCode(z);
return hash;
}
@Override
public String toString() {
return "Mutable (" + x + ", " + y + ", " + z + ")";
}
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
stream.writeDouble(x);
stream.writeByte((byte) y);
stream.writeDouble(z);
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
this.x = stream.readDouble();
this.y = stream.readByte() & 0xFF;
this.z = stream.readDouble();
}
}

View File

@ -0,0 +1,70 @@
package com.sk89q.worldedit.math;
import java.io.Serializable;
public class MutableVector2 extends Vector2 {
public MutableVector2() {}
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
public MutableVector2(double x, double z) {
super(x, z);
}
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
public MutableVector2(float x, float z) {
super(x, z);
}
/**
* Copy another vector.
*
* @param other the other vector
*/
public MutableVector2(Vector2 other) {
super(other);
}
@Override
public MutableVector2 setComponents(int x, int z) {
this.x = x;
this.z = z;
return this;
}
@Override
public MutableVector2 setComponents(double x, double z) {
this.x = x;
this.z = z;
return this;
}
@Override
public MutableVector2 mutX(int x) {
this.x = x;
return this;
}
@Override
public MutableVector2 mutZ(int z) {
this.z = z;
return this;
}
@Override
public MutableVector2 mutX(double x) {
this.x = x;
return this;
}
@Override
public MutableVector2 mutZ(double z) {
this.z = z;
return this;
}
}

View File

@ -0,0 +1,82 @@
package com.sk89q.worldedit.math;
import javax.annotation.Nullable;
public class MutableVector3 extends Vector3 {
public MutableVector3() {}
public MutableVector3(double x, double y, double z) {
super(x, y, z);
}
public MutableVector3(float x, float y, float z) {
super(x, y, z);
}
public MutableVector3(Vector3 other) {
super(other);
}
@Override
public MutableVector3 setComponents(Vector3 other) {
this.x = other.x;
this.y = other.y;
this.z = other.z;
return this;
}
@Override
public MutableVector3 setComponents(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public MutableVector3 setComponents(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public MutableVector3 mutX(int x) {
this.x = x;
return this;
}
@Override
public MutableVector3 mutZ(int z) {
this.z = z;
return this;
}
@Override
public MutableVector3 mutX(double x) {
this.x = x;
return this;
}
@Override
public MutableVector3 mutZ(double z) {
this.z = z;
return this;
}
@Override
public MutableVector3 mutY(int y) {
this.y = y;
return this;
}
@Override
public MutableVector3 mutY(double y) {
this.y = y;
return this;
}
public double getY() {
return y;
}
}

View File

@ -19,12 +19,13 @@
package com.sk89q.worldedit.math;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.transform.AffineTransform;
/**
* An immutable 2-dimensional vector.
*/
public final class Vector2 {
public class Vector2 {
public static final Vector2 ZERO = new Vector2(0, 0);
public static final Vector2 UNIT_X = new Vector2(1, 0);
@ -32,23 +33,12 @@ public final class Vector2 {
public static final Vector2 ONE = new Vector2(1, 1);
public static Vector2 at(double x, double z) {
int xTrunc = (int) x;
switch (xTrunc) {
case 0:
if (x == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && z == 1) {
return ONE;
}
break;
}
return new Vector2(x, z);
}
private final double x, z;
protected double x, z;
protected Vector2(){}
/**
* Construct an instance.
@ -56,11 +46,48 @@ public final class Vector2 {
* @param x the X coordinate
* @param z the Z coordinate
*/
private Vector2(double x, double z) {
protected Vector2(double x, double z) {
this.x = x;
this.z = z;
}
protected Vector2(Vector2 other) {
this.x = other.x;
this.z = other.z;
}
public int getBlockX() {
return MathMan.roundInt(getX());
}
public int getBlockZ() {
return MathMan.roundInt(getZ());
}
public MutableVector2 setComponents(int x, int z) {
return new MutableVector2(x, z);
}
public MutableVector2 setComponents(double x, double z) {
return new MutableVector2(x, z);
}
public MutableVector2 mutX(int x) {
return new MutableVector2(x, z);
}
public MutableVector2 mutZ(int z) {
return new MutableVector2(x, z);
}
public MutableVector2 mutX(double x) {
return new MutableVector2(x, z);
}
public MutableVector2 mutZ(double z) {
return new MutableVector2(x, z);
}
/**
* Get the X coordinate.
*
@ -458,21 +485,18 @@ public final class Vector2 {
}
Vector2 other = (Vector2) obj;
return other.x == this.x && other.z == this.z;
return other.getX() == this.getX() && other.getZ() == this.getZ();
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Double.hashCode(x);
hash = 31 * hash + Double.hashCode(z);
return hash;
return ((int) getX() ^ ((int) getZ() << 16));
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
return "(" + getX() + ", " + getZ() + ")";
}
}

View File

@ -21,9 +21,11 @@ package com.sk89q.worldedit.math;
import static com.google.common.base.Preconditions.checkArgument;
import com.boydti.fawe.util.MathMan;
import com.google.common.collect.ComparisonChain;
import com.sk89q.worldedit.math.transform.AffineTransform;
import javax.annotation.Nullable;
import java.util.Comparator;
/**
@ -38,21 +40,6 @@ public class Vector3 {
public static final Vector3 ONE = new Vector3(1, 1, 1);
public static Vector3 at(double x, double y, double z) {
// switch for efficiency on typical cases
// in MC y is rarely 0/1 on selections
int yTrunc = (int) y;
switch (yTrunc) {
case 0:
if (x == 0 && y == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && y == 1 && z == 1) {
return ONE;
}
break;
}
return new Vector3(x, y, z);
}
@ -77,7 +64,7 @@ public class Vector3 {
return YzxOrderComparator.YZX_ORDER;
}
private final double x, y, z;
protected double x, y, z;
/**
* Construct an instance.
@ -86,12 +73,68 @@ public class Vector3 {
* @param y the Y coordinate
* @param z the Z coordinate
*/
private Vector3(double x, double y, double z) {
protected Vector3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
protected Vector3() {}
protected Vector3(Vector3 other) {
this.x = other.x;
this.y = other.y;
this.z = other.z;
}
public int getBlockX() {
return MathMan.roundInt(getX());
}
public int getBlockY() {
return MathMan.roundInt(getY());
}
public int getBlockZ() {
return MathMan.roundInt(getZ());
}
public MutableVector3 setComponents(Vector3 other) {
return new MutableVector3(other);
}
public MutableVector3 setComponents(int x, int y, int z) {
return new MutableVector3(x, y, z);
}
public MutableVector3 setComponents(double x, double y, double z) {
return new MutableVector3(x, y, z);
}
public MutableVector3 mutX(int x) {
return new MutableVector3(x, y, getZ());
}
public MutableVector3 mutX(double x) {
return new MutableVector3(x, y, getZ());
}
public MutableVector3 mutY(int y) {
return new MutableVector3(getX(), y, getZ());
}
public MutableVector3 mutY(double y) {
return new MutableVector3(getX(), y, getZ());
}
public MutableVector3 mutZ(int z) {
return new MutableVector3(getX(), y, z);
}
public MutableVector3 mutZ(double z) {
return new MutableVector3(getX(), y, z);
}
/**
* Get the X coordinate.
*
@ -579,25 +622,25 @@ public class Vector3 {
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof Vector3)) {
return false;
}
Vector3 other = (Vector3) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
return other.getX() == this.getX() && other.getZ() == this.getZ() && other.getY() == this.getY();
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Double.hashCode(x);
hash = 31 * hash + Double.hashCode(y);
hash = 31 * hash + Double.hashCode(z);
return hash;
return ((int) getX() ^ ((int) getZ() << 16)) ^ ((int) getY() << 30);
}
@Override
public String toString() {
String x = (getX() == getBlockX() ? "" + getBlockX() : "" + getX());
String y = (getY() == getBlockY() ? "" + getBlockY() : "" + getY());
String z = (getZ() == getBlockZ() ? "" + getBlockZ() : "" + getZ());
return "(" + x + ", " + y + ", " + z + ")";
}

View File

@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
import java.util.Collections;
@ -139,7 +139,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
return nodes.get(index).getPosition();
}
private MutableBlockVector mutable = new MutableBlockVector();
private MutableBlockVector3 mutable = new MutableBlockVector3();
@Override
public Vector3 getPosition(double position) {

View File

@ -5,7 +5,7 @@ import java.io.Serializable;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MathUtils;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
/**
@ -17,7 +17,7 @@ import com.sk89q.worldedit.math.Vector3;
*/
public class AffineTransform implements Transform, Serializable {
private transient MutableBlockVector mutable = new MutableBlockVector();
private transient MutableBlockVector3 mutable = new MutableBlockVector3();
/**
* coefficients for x coordinate.
@ -324,7 +324,7 @@ public class AffineTransform implements Transform, Serializable {
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
mutable = new MutableBlockVector();
mutable = new MutableBlockVector3();
}

View File

@ -5,7 +5,7 @@ import com.sk89q.worldedit.math.Vector3;
public class RoundedTransform implements Transform{
private final Transform transform;
// private MutableBlockVector mutable = new MutableBlockVector();
// private MutableBlockVector3 mutable = new MutableBlockVector3();
public RoundedTransform(Transform transform) {
this.transform = transform;

View File

@ -43,7 +43,7 @@ public final class Transforms {
public static Location transform(Location location, Transform transform) {
checkNotNull(location);
checkNotNull(transform);
return new Location(location.getExtent(), transform.apply(location.toVector()), location.getDirection());
return new Location(location.getExtent(), transform.apply(location), location.getDirection());
}
}

View File

@ -20,17 +20,14 @@
package com.sk89q.worldedit.regions;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector2D;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector2;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
@ -320,7 +317,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public Iterator<BlockVector2> iterator() {
return new Iterator<BlockVector2>() {
private MutableBlockVector2D pos = new MutableBlockVector2D().setComponents(maxX + 1, maxZ);
private MutableBlockVector2 pos = new MutableBlockVector2().setComponents(maxX + 1, maxZ);
@Override
public boolean hasNext() {
@ -329,7 +326,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector2 next() {
MutableBlockVector2D result = pos;
MutableBlockVector2 result = pos;
// calc next
pos.setComponents(pos.getX() - 1, pos.getZ());
if (pos.getX() <= minX) {
@ -339,7 +336,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
pos.setComponents(maxX, pos.getZ() - 1);
}
}
return result.toBlockVector2();
return result;
}
@Override
@ -437,7 +434,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return iterator_old();
}
return new Iterator<BlockVector3>() {
final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
final MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();
@ -492,7 +489,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
x = tx;
y = ty;
hasNext = false;
return mutable.toBlockVector3();
return mutable;
}
} else {
z = cbz;
@ -521,13 +518,13 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
x = cbx;
}
}
return mutable.toBlockVector3();
return mutable;
}
};
}
public Iterator<BlockVector3> iterator_old() {
final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
final MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
return new Iterator<BlockVector3>() {
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();
@ -573,7 +570,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
}
}
return mutable.toBlockVector3();
return mutable;
}
};
}
@ -583,7 +580,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return new Iterable<BlockVector2>() {
@Override
public Iterator<BlockVector2> iterator() {
MutableBlockVector2D mutable = new MutableBlockVector2D();
MutableBlockVector2 mutable = new MutableBlockVector2();
return new Iterator<BlockVector2>() {
private BlockVector3 min = getMinimumPoint();
private BlockVector3 max = getMaximumPoint();

View File

@ -306,7 +306,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ();
return dx * dx + dz * dz <= 1;
// return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1;
// return position.subtract(center).toVector2().divide(radius).lengthSq() <= 1;
}

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;

View File

@ -23,12 +23,13 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.math.Vector3;
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
private final Vector3 unit;
private final Vector3 zero2;
private Vector3 current = Vector3.ZERO;
private Vector3 current = new MutableVector3(Vector3.ZERO);
private EditSession editSession;
private Extent extent;
@ -81,6 +82,10 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
}
public void setCurrentBlock(int x, int y, int z) {
current.setComponents(x, y, z);
}
public void setCurrentBlock(Vector3 current) {
this.current = current;
}

View File

@ -34,10 +34,9 @@ import com.sk89q.worldedit.math.Vector3;
* {@link #equals(Object)} are subject to minor differences caused by
* floating point errors.</p>
*/
public class Location{
public class Location extends Vector3 {
private final Extent extent;
private final Vector3 position;
private final float pitch;
private final float yaw;
@ -127,10 +126,10 @@ public class Location{
*/
public Location(Extent extent, Vector3 position, float yaw, float pitch) {
super(position);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
this.pitch = pitch;
this.yaw = yaw;
}
@ -151,7 +150,7 @@ public class Location{
* @return the new instance
*/
public Location setExtent(Extent extent) {
return new Location(extent, position, getDirection());
return new Location(extent, this, getDirection());
}
/**
@ -170,7 +169,7 @@ public class Location{
* @return the new instance
*/
public Location setYaw(float yaw) {
return new Location(extent, position, yaw, pitch);
return new Location(extent, this, yaw, pitch);
}
/**
@ -189,7 +188,7 @@ public class Location{
* @return the new instance
*/
public Location setPitch(float pitch) {
return new Location(extent, position, yaw, pitch);
return new Location(extent, this, yaw, pitch);
}
/**
@ -200,7 +199,7 @@ public class Location{
* @return the new instance
*/
public Location setDirection(float yaw, float pitch) {
return new Location(extent, position, yaw, pitch);
return new Location(extent, this, yaw, pitch);
}
/**
@ -234,7 +233,7 @@ public class Location{
* @return the new instance
*/
public Location setDirection(Vector3 direction) {
return new Location(extent, position, (float) direction.toYaw(), (float) direction.toPitch());
return new Location(extent, this, (float) direction.toYaw(), (float) direction.toPitch());
}
/**
@ -242,8 +241,8 @@ public class Location{
*
* @return a vector
*/
public Vector3 toVector() {
return position;
public Vector3 vector() {
return this;
}
/**
@ -252,7 +251,7 @@ public class Location{
* @return the X component
*/
public double getX() {
return position.getX();
return this.getX();
}
/**
@ -261,7 +260,7 @@ public class Location{
* @return the rounded X component
*/
public int getBlockX() {
return (int) Math.floor(position.getX());
return (int) Math.floor(this.getX());
}
/**
@ -272,7 +271,7 @@ public class Location{
* @return a new immutable instance
*/
public Location setX(double x) {
return new Location(extent, position.withX(x), yaw, pitch);
return new Location(extent, this.withX(x), yaw, pitch);
}
/**
@ -281,7 +280,7 @@ public class Location{
* @return the Y component
*/
public double getY() {
return position.getY();
return this.getY();
}
/**
@ -290,7 +289,7 @@ public class Location{
* @return the rounded Y component
*/
public int getBlockY() {
return (int) Math.floor(position.getY());
return (int) Math.floor(this.getY());
}
/**
@ -301,7 +300,7 @@ public class Location{
* @return a new immutable instance
*/
public Location setY(double y) {
return new Location(extent, position.withY(y), yaw, pitch);
return new Location(extent, this.withY(y), yaw, pitch);
}
/**
@ -310,7 +309,7 @@ public class Location{
* @return the Z component
*/
public double getZ() {
return position.getZ();
return this.getZ();
}
/**
@ -319,7 +318,7 @@ public class Location{
* @return the rounded Z component
*/
public int getBlockZ() {
return (int) Math.floor(position.getZ());
return (int) Math.floor(this.getZ());
}
/**
@ -330,7 +329,7 @@ public class Location{
* @return a new immutable instance
*/
public Location setZ(double z) {
return new Location(extent, position.withZ(z), yaw, pitch);
return new Location(extent, this.withZ(z), yaw, pitch);
}
/**

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.util;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -49,7 +48,7 @@ public class TargetBlock {
*/
public TargetBlock(Player player) {
this.world = player.getWorld();
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), 300, 1.65, 0.2);
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), 300, 1.65, 0.2);
}
/**
@ -61,7 +60,7 @@ public class TargetBlock {
*/
public TargetBlock(Player player, int maxDistance, double checkDistance) {
this.world = player.getWorld();
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
}
/**
@ -189,12 +188,12 @@ public class TargetBlock {
public Location getAnyTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector()));
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
}
public Location getTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector()));
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
}
}