mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Current progress with update
This commit is contained in:
@ -19,8 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
@ -30,30 +30,30 @@ import java.util.HashMap;
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
NORTH(new Vector(0, 0, -1), Flag.CARDINAL, 3, 1),
|
||||
EAST(new Vector(1, 0, 0), Flag.CARDINAL, 0, 2),
|
||||
SOUTH(new Vector(0, 0, 1), Flag.CARDINAL, 1, 3),
|
||||
WEST(new Vector(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
||||
NORTH(new Vector3(0, 0, -1), Flag.CARDINAL, 3, 1),
|
||||
EAST(new Vector3(1, 0, 0), Flag.CARDINAL, 0, 2),
|
||||
SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL, 1, 3),
|
||||
WEST(new Vector3(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
||||
|
||||
UP(new Vector(0, 1, 0), Flag.UPRIGHT, -1, -1),
|
||||
DOWN(new Vector(0, -1, 0), Flag.UPRIGHT, -1, -1),
|
||||
UP(new Vector3(0, 1, 0), Flag.UPRIGHT, -1, -1),
|
||||
DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT, -1, -1),
|
||||
|
||||
NORTHEAST(new Vector(1, 0, -1), Flag.ORDINAL, 7, 8),
|
||||
NORTHWEST(new Vector(-1, 0, -1), Flag.ORDINAL, 9, 6),
|
||||
SOUTHEAST(new Vector(1, 0, 1), Flag.ORDINAL, 6, 9),
|
||||
SOUTHWEST(new Vector(-1, 0, 1), Flag.ORDINAL, 8, 7),
|
||||
NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL, 7, 8),
|
||||
NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL, 9, 6),
|
||||
SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL, 6, 9),
|
||||
SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL, 8, 7),
|
||||
|
||||
WEST_NORTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
|
||||
WEST_SOUTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7),
|
||||
NORTH_NORTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
|
||||
NORTH_NORTHEAST(new Vector(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
|
||||
EAST_NORTHEAST(new Vector(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
|
||||
EAST_SOUTHEAST(new Vector(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
|
||||
SOUTH_SOUTHEAST(new Vector(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
|
||||
SOUTH_SOUTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7);
|
||||
WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
|
||||
WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7),
|
||||
NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6),
|
||||
NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
|
||||
EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8),
|
||||
EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
|
||||
SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9),
|
||||
SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7);
|
||||
|
||||
private final Vector direction;
|
||||
private final BlockVector blockVector;
|
||||
private final Vector3 direction;
|
||||
private final BlockVector3 blockVector;
|
||||
private final int flags, left, right;
|
||||
|
||||
|
||||
@ -68,9 +68,9 @@ public enum Direction {
|
||||
}
|
||||
}
|
||||
|
||||
private Direction(Vector vector, int flags, int left, int right) {
|
||||
private Direction(Vector3 vector, int flags, int left, int right) {
|
||||
this.direction = vector.normalize();
|
||||
this.blockVector = new BlockVector(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
|
||||
this.blockVector = new BlockVector3(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
|
||||
this.flags = flags;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
@ -159,19 +159,24 @@ public enum Direction {
|
||||
*
|
||||
* @return the vector
|
||||
*/
|
||||
public Vector toVector() {
|
||||
public Vector3 toVector() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public BlockVector toBlockVector() {
|
||||
return this.blockVector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vector.
|
||||
*
|
||||
* @return the vector
|
||||
*/
|
||||
public BlockVector3 toBlockVector() {
|
||||
return direction.toBlockPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest direction to the given direction vector.
|
||||
*
|
||||
@ -180,9 +185,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();
|
||||
|
||||
@ -204,7 +209,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;
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a block located at some position.
|
||||
*/
|
||||
public final class LocatedBlock {
|
||||
|
||||
private final BlockVector3 location;
|
||||
private final BlockStateHolder block;
|
||||
|
||||
public LocatedBlock(BlockVector3 location, BlockStateHolder block) {
|
||||
this.location = checkNotNull(location);
|
||||
this.block = checkNotNull(block);
|
||||
}
|
||||
|
||||
public BlockVector3 getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public BlockStateHolder getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(location, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LocatedBlock lb = (LocatedBlock) obj;
|
||||
return Objects.equals(location, lb.location) && Objects.equals(block, lb.block);
|
||||
}
|
||||
|
||||
}
|
@ -19,12 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.NullWorld;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
* Represents a location in a world with has a direction.
|
||||
*
|
||||
@ -35,9 +34,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
* {@link #equals(Object)} are subject to minor differences caused by
|
||||
* floating point errors.</p>
|
||||
*/
|
||||
public class Location extends Vector {
|
||||
public class Location{
|
||||
|
||||
private final Extent extent;
|
||||
private final Vector3 position;
|
||||
private final float pitch;
|
||||
private final float yaw;
|
||||
|
||||
@ -48,7 +48,7 @@ public class Location extends Vector {
|
||||
* @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 extends Vector {
|
||||
* @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 extends Vector {
|
||||
* @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 extends Vector {
|
||||
* @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 extends Vector {
|
||||
* @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 extends Vector {
|
||||
* @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,10 +125,12 @@ public class Location extends Vector {
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
*/
|
||||
public Location(Extent extent, Vector position, float yaw, float pitch) {
|
||||
super(position);
|
||||
|
||||
public Location(Extent extent, Vector3 position, float yaw, float pitch) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(position);
|
||||
this.extent = extent;
|
||||
this.position = position;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
@ -149,7 +151,7 @@ public class Location extends Vector {
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setExtent(Extent extent) {
|
||||
return new Location(extent, this, getDirection());
|
||||
return new Location(extent, position, getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +170,7 @@ public class Location extends Vector {
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setYaw(float yaw) {
|
||||
return new Location(extent, this, yaw, pitch);
|
||||
return new Location(extent, position, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +189,7 @@ public class Location extends Vector {
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setPitch(float pitch) {
|
||||
return new Location(extent, this, yaw, pitch);
|
||||
return new Location(extent, position, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +200,7 @@ public class Location extends Vector {
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setDirection(float yaw, float pitch) {
|
||||
return new Location(extent, this, yaw, pitch);
|
||||
return new Location(extent, position, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,11 +208,11 @@ public class Location extends Vector {
|
||||
*
|
||||
* @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));
|
||||
@ -231,17 +233,35 @@ public class Location extends Vector {
|
||||
* @param direction the new direction
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setDirection(Vector direction) {
|
||||
return new Location(extent, this, 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() {
|
||||
return this;
|
||||
public Vector3 toVector() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X component of the position vector.
|
||||
*
|
||||
* @return the X component
|
||||
*/
|
||||
public double getX() {
|
||||
return position.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rounded X component of the position vector.
|
||||
*
|
||||
* @return the rounded X component
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return (int) Math.floor(position.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,18 +272,25 @@ public class Location extends Vector {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setX(double x) {
|
||||
return new Location(extent, super.setX(x), yaw, pitch);
|
||||
return new Location(extent, position.withX(x), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this object with the X component of the new object
|
||||
* set to the given value.
|
||||
* Get the Y component of the position vector.
|
||||
*
|
||||
* @param x the new value for the X component
|
||||
* @return a new immutable instance
|
||||
* @return the Y component
|
||||
*/
|
||||
public Location setX(int x) {
|
||||
return new Location(extent, super.setX(x), yaw, pitch);
|
||||
public double getY() {
|
||||
return position.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rounded Y component of the position vector.
|
||||
*
|
||||
* @return the rounded Y component
|
||||
*/
|
||||
public int getBlockY() {
|
||||
return (int) Math.floor(position.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,18 +301,25 @@ public class Location extends Vector {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setY(double y) {
|
||||
return new Location(extent, super.setY(y), yaw, pitch);
|
||||
return new Location(extent, position.withY(y), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this object with the Y component of the new object
|
||||
* set to the given value.
|
||||
* Get the Z component of the position vector.
|
||||
*
|
||||
* @param y the new value for the Y component
|
||||
* @return a new immutable instance
|
||||
* @return the Z component
|
||||
*/
|
||||
public Location setY(int y) {
|
||||
return new Location(extent, super.setY(y), yaw, pitch);
|
||||
public double getZ() {
|
||||
return position.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rounded Z component of the position vector.
|
||||
*
|
||||
* @return the rounded Z component
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return (int) Math.floor(position.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,18 +330,7 @@ public class Location extends Vector {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setZ(double z) {
|
||||
return new Location(extent, super.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, super.setZ(z), yaw, pitch);
|
||||
return new Location(extent, position.withZ(z), yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -316,7 +339,7 @@ public class Location extends Vector {
|
||||
* @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,13 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
<<<<<<< HEAD
|
||||
import com.sk89q.worldedit.*;
|
||||
=======
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
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 +40,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
|
||||
@ -72,8 +77,12 @@ 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
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
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) {
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
this.maxDistance = maxDistance;
|
||||
this.checkDistance = checkDistance;
|
||||
this.curDistance = 0;
|
||||
@ -82,9 +91,15 @@ public class TargetBlock {
|
||||
|
||||
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||
|
||||
<<<<<<< HEAD
|
||||
offset = new Vector((h * Math.cos(Math.toRadians(xRotation))),
|
||||
(checkDistance * Math.sin(Math.toRadians(yRotation))),
|
||||
(h * Math.sin(Math.toRadians(xRotation))));
|
||||
=======
|
||||
offset = new Vector3((h * Math.cos(Math.toRadians(xRotation))),
|
||||
(checkDistance * Math.sin(Math.toRadians(yRotation))),
|
||||
(h * Math.sin(Math.toRadians(xRotation))));
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
|
||||
targetPosDouble = loc.add(0, viewHeight, 0);
|
||||
targetPos = targetPosDouble.toBlockPoint();
|
||||
@ -101,7 +116,11 @@ public class TargetBlock {
|
||||
boolean searchForLastBlock = true;
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
<<<<<<< HEAD
|
||||
if (world.getBlockType(getCurrentBlock().toVector()).getMaterial().isAir()) {
|
||||
=======
|
||||
if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) {
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = getCurrentBlock();
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
@ -123,7 +142,11 @@ public class TargetBlock {
|
||||
* @return Block
|
||||
*/
|
||||
public Location getTargetBlock() {
|
||||
<<<<<<< HEAD
|
||||
while (getNextBlock() != null && world.getBlockType(getCurrentBlock().toVector()).getMaterial().isAir()) ;
|
||||
=======
|
||||
while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ;
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
@ -134,7 +157,11 @@ public class TargetBlock {
|
||||
* @return Block
|
||||
*/
|
||||
public Location getSolidTargetBlock() {
|
||||
<<<<<<< HEAD
|
||||
while (getNextBlock() != null && !world.getBlockType(getCurrentBlock().toVector()).getMaterial().isMovementBlocker()) ;
|
||||
=======
|
||||
while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ;
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
@ -161,7 +188,7 @@ public class TargetBlock {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Location(world, targetPos);
|
||||
return new Location(world, targetPos.toVector3());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +200,7 @@ public class TargetBlock {
|
||||
if (curDistance > maxDistance) {
|
||||
return null;
|
||||
} else {
|
||||
return new Location(world, targetPos);
|
||||
return new Location(world, targetPos.toVector3());
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +210,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,8 @@ 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.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -49,7 +50,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 +59,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 +68,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 +84,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 +94,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 +140,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 +175,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 +251,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 +264,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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.collection;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.LocatedBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Wrapper around a list of blocks located in the world.
|
||||
*/
|
||||
public class LocatedBlockList implements Iterable<LocatedBlock> {
|
||||
|
||||
private final List<LocatedBlock> list;
|
||||
|
||||
public LocatedBlockList() {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
||||
public LocatedBlockList(Collection<? extends LocatedBlock> collection) {
|
||||
list = new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
public void add(LocatedBlock setBlockCall) {
|
||||
checkNotNull(setBlockCall);
|
||||
list.add(setBlockCall);
|
||||
}
|
||||
|
||||
public void add(BlockVector3 location, BlockStateHolder block) {
|
||||
add(new LocatedBlock(location, block));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<LocatedBlock> iterator() {
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
public Iterator<LocatedBlock> reverseIterator() {
|
||||
return new Iterator<LocatedBlock>() {
|
||||
|
||||
private final ListIterator<LocatedBlock> backingIterator = list.listIterator(list.size());
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return backingIterator.hasPrevious();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatedBlock next() {
|
||||
return backingIterator.previous();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -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