mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Refactor vector system to be cleaner
- Move Vector, etc. into `.math` package - Drop many methods that will be auto-promoted anyways, eg. with `divide(int)` and `divide(double)` the first is now gone. - Take Block vectors into their own class hierarchy - Make it clear throughout the API what takes blockvectors - many more improvements
This commit is contained in:
@ -19,7 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -28,32 +29,32 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
NORTH(new Vector(0, 0, -1), Flag.CARDINAL),
|
||||
EAST(new Vector(1, 0, 0), Flag.CARDINAL),
|
||||
SOUTH(new Vector(0, 0, 1), Flag.CARDINAL),
|
||||
WEST(new Vector(-1, 0, 0), Flag.CARDINAL),
|
||||
NORTH(new Vector3(0, 0, -1), Flag.CARDINAL),
|
||||
EAST(new Vector3(1, 0, 0), Flag.CARDINAL),
|
||||
SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL),
|
||||
WEST(new Vector3(-1, 0, 0), Flag.CARDINAL),
|
||||
|
||||
UP(new Vector(0, 1, 0), Flag.UPRIGHT),
|
||||
DOWN(new Vector(0, -1, 0), Flag.UPRIGHT),
|
||||
UP(new Vector3(0, 1, 0), Flag.UPRIGHT),
|
||||
DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT),
|
||||
|
||||
NORTHEAST(new Vector(1, 0, -1), Flag.ORDINAL),
|
||||
NORTHWEST(new Vector(-1, 0, -1), Flag.ORDINAL),
|
||||
SOUTHEAST(new Vector(1, 0, 1), Flag.ORDINAL),
|
||||
SOUTHWEST(new Vector(-1, 0, 1), Flag.ORDINAL),
|
||||
NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL),
|
||||
NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL),
|
||||
SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL),
|
||||
SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL),
|
||||
|
||||
WEST_NORTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
WEST_SOUTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
NORTH_NORTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
NORTH_NORTHEAST(new Vector(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
EAST_NORTHEAST(new Vector(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
EAST_SOUTHEAST(new Vector(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
SOUTH_SOUTHEAST(new Vector(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
SOUTH_SOUTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL);
|
||||
WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL),
|
||||
SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL);
|
||||
|
||||
private final Vector direction;
|
||||
private final Vector3 direction;
|
||||
private final int flags;
|
||||
|
||||
Direction(Vector vector, int flags) {
|
||||
Direction(Vector3 vector, int flags) {
|
||||
this.direction = vector.normalize();
|
||||
this.flags = flags;
|
||||
}
|
||||
@ -105,10 +106,19 @@ public enum Direction {
|
||||
*
|
||||
* @return the vector
|
||||
*/
|
||||
public Vector toVector() {
|
||||
public Vector3 toVector() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vector.
|
||||
*
|
||||
* @return the vector
|
||||
*/
|
||||
public BlockVector3 toBlockVector() {
|
||||
return direction.toBlockPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest direction to the given direction vector.
|
||||
*
|
||||
@ -117,9 +127,9 @@ public enum Direction {
|
||||
* @return the closest direction, or null if no direction can be returned
|
||||
*/
|
||||
@Nullable
|
||||
public static Direction findClosest(Vector vector, int flags) {
|
||||
public static Direction findClosest(Vector3 vector, int flags) {
|
||||
if ((flags & Flag.UPRIGHT) == 0) {
|
||||
vector = vector.setY(0);
|
||||
vector = vector.withY(0);
|
||||
}
|
||||
vector = vector.normalize();
|
||||
|
||||
@ -141,7 +151,7 @@ public enum Direction {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags to use with {@link #findClosest(Vector, int)}.
|
||||
* Flags to use with {@link #findClosest(Vector3, int)}.
|
||||
*/
|
||||
public static final class Flag {
|
||||
public static int CARDINAL = 0x1;
|
||||
|
@ -21,7 +21,7 @@ package com.sk89q.worldedit.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -31,15 +31,15 @@ import java.util.Objects;
|
||||
*/
|
||||
public final class LocatedBlock {
|
||||
|
||||
private final Vector location;
|
||||
private final BlockVector3 location;
|
||||
private final BlockStateHolder block;
|
||||
|
||||
public LocatedBlock(Vector location, BlockStateHolder block) {
|
||||
public LocatedBlock(BlockVector3 location, BlockStateHolder block) {
|
||||
this.location = checkNotNull(location);
|
||||
this.block = checkNotNull(block);
|
||||
}
|
||||
|
||||
public Vector getLocation() {
|
||||
public BlockVector3 getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,8 @@ package com.sk89q.worldedit.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
* Represents a location in a world with has a direction.
|
||||
@ -37,7 +37,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
public class Location {
|
||||
|
||||
private final Extent extent;
|
||||
private final Vector position;
|
||||
private final Vector3 position;
|
||||
private final float pitch;
|
||||
private final float yaw;
|
||||
|
||||
@ -48,7 +48,7 @@ public class Location {
|
||||
* @param extent the extent
|
||||
*/
|
||||
public Location(Extent extent) {
|
||||
this(extent, new Vector(), new Vector());
|
||||
this(extent, Vector3.ZERO, Vector3.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +61,7 @@ public class Location {
|
||||
* @param z the Z coordinate
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z) {
|
||||
this(extent, new Vector(x, y, z), new Vector());
|
||||
this(extent, new Vector3(x, y, z), Vector3.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,8 +71,8 @@ public class Location {
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
*/
|
||||
public Location(Extent extent, Vector position) {
|
||||
this(extent, position, new Vector());
|
||||
public Location(Extent extent, Vector3 position) {
|
||||
this(extent, position, Vector3.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,8 +85,8 @@ public class Location {
|
||||
* @param z the Z coordinate
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z, Vector direction) {
|
||||
this(extent, new Vector(x, y, z), direction);
|
||||
public Location(Extent extent, double x, double y, double z, Vector3 direction) {
|
||||
this(extent, new Vector3(x, y, z), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +101,7 @@ public class Location {
|
||||
* @param pitch the pitch, in degrees
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z, float yaw, float pitch) {
|
||||
this(extent, new Vector(x, y, z), yaw, pitch);
|
||||
this(extent, new Vector3(x, y, z), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,8 +112,8 @@ public class Location {
|
||||
* @param position the position vector
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(Extent extent, Vector position, Vector direction) {
|
||||
this(extent, position, direction.toYaw(), direction.toPitch());
|
||||
public Location(Extent extent, Vector3 position, Vector3 direction) {
|
||||
this(extent, position, (float) direction.toYaw(), (float) direction.toPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +125,7 @@ public class Location {
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
*/
|
||||
public Location(Extent extent, Vector position, float yaw, float pitch) {
|
||||
public Location(Extent extent, Vector3 position, float yaw, float pitch) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(position);
|
||||
this.extent = extent;
|
||||
@ -207,11 +207,11 @@ public class Location {
|
||||
*
|
||||
* @return the direction vector
|
||||
*/
|
||||
public Vector getDirection() {
|
||||
public Vector3 getDirection() {
|
||||
double yaw = Math.toRadians(this.getYaw());
|
||||
double pitch = Math.toRadians(this.getPitch());
|
||||
double xz = Math.cos(pitch);
|
||||
return new Vector(
|
||||
return new Vector3(
|
||||
-xz * Math.sin(yaw),
|
||||
-Math.sin(pitch),
|
||||
xz * Math.cos(yaw));
|
||||
@ -232,16 +232,16 @@ public class Location {
|
||||
* @param direction the new direction
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setDirection(Vector direction) {
|
||||
return new Location(extent, position, direction.toYaw(), direction.toPitch());
|
||||
public Location setDirection(Vector3 direction) {
|
||||
return new Location(extent, position, (float) direction.toYaw(), (float) direction.toPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Vector} form of this location's position.
|
||||
* Get a {@link Vector3} form of this location's position.
|
||||
*
|
||||
* @return a vector
|
||||
*/
|
||||
public Vector toVector() {
|
||||
public Vector3 toVector() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ public class Location {
|
||||
* @return the rounded X component
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return position.getBlockX();
|
||||
return (int) Math.floor(position.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,18 +271,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setX(double x) {
|
||||
return new Location(extent, position.setX(x), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this object with the X component of the new object
|
||||
* set to the given value.
|
||||
*
|
||||
* @param x the new value for the X component
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setX(int x) {
|
||||
return new Location(extent, position.setX(x), yaw, pitch);
|
||||
return new Location(extent, position.withX(x), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -300,7 +289,7 @@ public class Location {
|
||||
* @return the rounded Y component
|
||||
*/
|
||||
public int getBlockY() {
|
||||
return position.getBlockY();
|
||||
return (int) Math.floor(position.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,18 +300,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setY(double y) {
|
||||
return new Location(extent, position.setY(y), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this object with the Y component of the new object
|
||||
* set to the given value.
|
||||
*
|
||||
* @param y the new value for the Y component
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setY(int y) {
|
||||
return new Location(extent, position.setY(y), yaw, pitch);
|
||||
return new Location(extent, position.withY(y), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -340,7 +318,7 @@ public class Location {
|
||||
* @return the rounded Z component
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return position.getBlockZ();
|
||||
return (int) Math.floor(position.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,18 +329,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setZ(double z) {
|
||||
return new Location(extent, position.setZ(z), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this object with the Z component of the new object
|
||||
* set to the given value.
|
||||
*
|
||||
* @param z the new value for the Y component
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setZ(int z) {
|
||||
return new Location(extent, position.setZ(z), yaw, pitch);
|
||||
return new Location(extent, position.withZ(z), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -371,7 +338,7 @@ public class Location {
|
||||
* @param position The new position
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setPosition(Vector position) {
|
||||
public Location setPosition(Vector3 position) {
|
||||
return new Location(extent, position, yaw, pitch);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
@ -35,10 +36,10 @@ public class TargetBlock {
|
||||
private World world;
|
||||
private int maxDistance;
|
||||
private double checkDistance, curDistance;
|
||||
private Vector targetPos = new Vector();
|
||||
private Vector targetPosDouble = new Vector();
|
||||
private Vector prevPos = new Vector();
|
||||
private Vector offset = new Vector();
|
||||
private BlockVector3 targetPos = BlockVector3.ZERO;
|
||||
private Vector3 targetPosDouble = Vector3.ZERO;
|
||||
private BlockVector3 prevPos = BlockVector3.ZERO;
|
||||
private Vector3 offset = Vector3.ZERO;
|
||||
|
||||
/**
|
||||
* Constructor requiring a player, uses default values
|
||||
@ -73,7 +74,7 @@ public class TargetBlock {
|
||||
* @param viewHeight where the view is positioned in y-axis
|
||||
* @param checkDistance how often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
private void setValues(Vector loc, double xRotation, double yRotation, int maxDistance, double viewHeight, double checkDistance) {
|
||||
private void setValues(Vector3 loc, double xRotation, double yRotation, int maxDistance, double viewHeight, double checkDistance) {
|
||||
this.maxDistance = maxDistance;
|
||||
this.checkDistance = checkDistance;
|
||||
this.curDistance = 0;
|
||||
@ -82,7 +83,7 @@ public class TargetBlock {
|
||||
|
||||
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||
|
||||
offset = new Vector((h * Math.cos(Math.toRadians(xRotation))),
|
||||
offset = new Vector3((h * Math.cos(Math.toRadians(xRotation))),
|
||||
(checkDistance * Math.sin(Math.toRadians(yRotation))),
|
||||
(h * Math.sin(Math.toRadians(xRotation))));
|
||||
|
||||
@ -101,7 +102,7 @@ public class TargetBlock {
|
||||
boolean searchForLastBlock = true;
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
if (world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) {
|
||||
if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) {
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = getCurrentBlock();
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
@ -123,7 +124,7 @@ public class TargetBlock {
|
||||
* @return Block
|
||||
*/
|
||||
public Location getTargetBlock() {
|
||||
while (getNextBlock() != null && world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) ;
|
||||
while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ;
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
@ -134,7 +135,7 @@ public class TargetBlock {
|
||||
* @return Block
|
||||
*/
|
||||
public Location getSolidTargetBlock() {
|
||||
while (getNextBlock() != null && !world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isMovementBlocker()) ;
|
||||
while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ;
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
@ -161,7 +162,7 @@ public class TargetBlock {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Location(world, targetPos);
|
||||
return new Location(world, targetPos.toVector3());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +174,7 @@ public class TargetBlock {
|
||||
if (curDistance > maxDistance) {
|
||||
return null;
|
||||
} else {
|
||||
return new Location(world, targetPos);
|
||||
return new Location(world, targetPos.toVector3());
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +184,7 @@ public class TargetBlock {
|
||||
* @return block position
|
||||
*/
|
||||
public Location getPreviousBlock() {
|
||||
return new Location(world, prevPos);
|
||||
return new Location(world, prevPos.toVector3());
|
||||
}
|
||||
|
||||
public Location getAnyTargetBlockFace() {
|
||||
|
@ -22,7 +22,7 @@ package com.sk89q.worldedit.util;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -49,7 +49,7 @@ public class TreeGenerator {
|
||||
MEGA_REDWOOD("Large spruce tree", "largespruce", "megaredwood"),
|
||||
RANDOM_REDWOOD("Random spruce tree", "randspruce", "randredwood", "randomredwood", "anyredwood") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { REDWOOD, TALL_REDWOOD, MEGA_REDWOOD };
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
@ -58,7 +58,7 @@ public class TreeGenerator {
|
||||
TALL_BIRCH("Tall birch tree", "tallbirch"),
|
||||
RANDOM_BIRCH("Random birch tree", "randbirch", "randombirch") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { BIRCH, TALL_BIRCH };
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
@ -67,13 +67,13 @@ public class TreeGenerator {
|
||||
SMALL_JUNGLE("Small jungle tree", "shortjungle", "smalljungle"),
|
||||
SHORT_JUNGLE("Short jungle tree") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
return SMALL_JUNGLE.generate(editSession, pos);
|
||||
}
|
||||
},
|
||||
RANDOM_JUNGLE("Random jungle tree", "randjungle", "randomjungle") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { JUNGLE, SMALL_JUNGLE };
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
@ -83,7 +83,7 @@ public class TreeGenerator {
|
||||
BROWN_MUSHROOM("Brown mushroom", "brownmushroom", "browngiantmushroom"),
|
||||
RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { RED_MUSHROOM, BROWN_MUSHROOM };
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
@ -93,14 +93,14 @@ public class TreeGenerator {
|
||||
DARK_OAK("Dark oak tree", "darkoak"),
|
||||
PINE("Pine tree", "pine") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
makePineTree(editSession, pos);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
RANDOM("Random tree", "rand", "random") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = TreeType.values();
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class TreeGenerator {
|
||||
return Collections.unmodifiableSet(primaryAliases);
|
||||
}
|
||||
|
||||
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
return editSession.getWorld().generateTree(this, editSession, pos);
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class TreeGenerator {
|
||||
*
|
||||
* @param basePosition the base position
|
||||
*/
|
||||
private static void makePineTree(EditSession editSession, Vector basePosition)
|
||||
private static void makePineTree(EditSession editSession, BlockVector3 basePosition)
|
||||
throws MaxChangedBlocksException {
|
||||
int trunkHeight = (int) Math.floor(Math.random() * 2) + 3;
|
||||
int height = (int) Math.floor(Math.random() * 5) + 8;
|
||||
@ -250,7 +250,7 @@ public class TreeGenerator {
|
||||
* @return whether a block was changed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
private static boolean setChanceBlockIfAir(EditSession session, Vector position, BlockStateHolder block, double probability)
|
||||
private static boolean setChanceBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block, double probability)
|
||||
throws MaxChangedBlocksException {
|
||||
return Math.random() <= probability && setBlockIfAir(session, position, block);
|
||||
}
|
||||
@ -263,7 +263,7 @@ public class TreeGenerator {
|
||||
* @return if block was changed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException {
|
||||
private static boolean setBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException {
|
||||
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package com.sk89q.worldedit.util.collection;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.LocatedBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
@ -51,7 +51,7 @@ public class LocatedBlockList implements Iterable<LocatedBlock> {
|
||||
list.add(setBlockCall);
|
||||
}
|
||||
|
||||
public void add(Vector location, BlockStateHolder block) {
|
||||
public void add(BlockVector3 location, BlockStateHolder block) {
|
||||
add(new LocatedBlock(location, block));
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ package com.sk89q.worldedit.util.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
* Utility methods for Google's GSON library.
|
||||
@ -38,7 +38,7 @@ public final class GsonUtil {
|
||||
*/
|
||||
public static GsonBuilder createBuilder() {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
return gsonBuilder;
|
||||
}
|
||||
|
||||
|
@ -24,17 +24,17 @@ import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Deserializes {@code Vector}s for GSON.
|
||||
*/
|
||||
public class VectorAdapter implements JsonDeserializer<Vector> {
|
||||
public class VectorAdapter implements JsonDeserializer<Vector3> {
|
||||
|
||||
@Override
|
||||
public Vector deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
public Vector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonArray jsonArray = json.getAsJsonArray();
|
||||
if (jsonArray.size() != 3) {
|
||||
throw new JsonParseException("Expected array of 3 length for Vector");
|
||||
@ -44,6 +44,6 @@ public class VectorAdapter implements JsonDeserializer<Vector> {
|
||||
double y = jsonArray.get(1).getAsDouble();
|
||||
double z = jsonArray.get(2).getAsDouble();
|
||||
|
||||
return new Vector(x, y, z);
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user