Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Finish removal of PlayerDirection, and partially added diagonal support back to commands.
Dieser Commit ist enthalten in:
Ursprung
bf98dcff09
Commit
24800a662a
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
|
||||||
import com.sk89q.worldedit.util.Direction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The player's direction.
|
|
||||||
*
|
|
||||||
* <p>In the future, this class will be replaced with {@link Direction}.</p>
|
|
||||||
*/
|
|
||||||
public enum PlayerDirection {
|
|
||||||
|
|
||||||
NORTH(Vector3.at(0, 0, -1), true),
|
|
||||||
NORTH_EAST((Vector3.at(1, 0, -1)).normalize(), false),
|
|
||||||
EAST(Vector3.at(1, 0, 0), true),
|
|
||||||
SOUTH_EAST((Vector3.at(1, 0, 1)).normalize(), false),
|
|
||||||
SOUTH(Vector3.at(0, 0, 1), true),
|
|
||||||
SOUTH_WEST((Vector3.at(-1, 0, 1)).normalize(), false),
|
|
||||||
WEST(Vector3.at(-1, 0, 0), true),
|
|
||||||
NORTH_WEST((Vector3.at(-1, 0, -1)).normalize(), false),
|
|
||||||
UP(Vector3.at(0, 1, 0), true),
|
|
||||||
DOWN(Vector3.at(0, -1, 0), true);
|
|
||||||
|
|
||||||
private final Vector3 dir;
|
|
||||||
private final boolean isOrthogonal;
|
|
||||||
|
|
||||||
PlayerDirection(Vector3 vec, boolean isOrthogonal) {
|
|
||||||
this.dir = vec;
|
|
||||||
this.isOrthogonal = isOrthogonal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 vector() {
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOrthogonal() {
|
|
||||||
return isOrthogonal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -46,6 +46,7 @@ import com.sk89q.worldedit.scripting.CraftScriptEngine;
|
|||||||
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
|
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
|
||||||
import com.sk89q.worldedit.session.SessionManager;
|
import com.sk89q.worldedit.session.SessionManager;
|
||||||
import com.sk89q.worldedit.session.request.Request;
|
import com.sk89q.worldedit.session.request.Request;
|
||||||
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||||
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
|
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
|
||||||
@ -374,22 +375,36 @@ public class WorldEdit {
|
|||||||
public BlockVector3 getDirection(Player player, String dirStr) throws UnknownDirectionException {
|
public BlockVector3 getDirection(Player player, String dirStr) throws UnknownDirectionException {
|
||||||
dirStr = dirStr.toLowerCase();
|
dirStr = dirStr.toLowerCase();
|
||||||
|
|
||||||
final PlayerDirection dir = getPlayerDirection(player, dirStr);
|
final Direction dir = getPlayerDirection(player, dirStr);
|
||||||
|
|
||||||
switch (dir) {
|
if (dir.isUpright() || dir.isCardinal()) {
|
||||||
case WEST:
|
return dir.toBlockVector();
|
||||||
case EAST:
|
} else {
|
||||||
case SOUTH:
|
|
||||||
case NORTH:
|
|
||||||
case UP:
|
|
||||||
case DOWN:
|
|
||||||
return dir.vector().toBlockPoint();
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new UnknownDirectionException(dir.name());
|
throw new UnknownDirectionException(dir.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the direction vector for a player's direction. May return
|
||||||
|
* null if a direction could not be found.
|
||||||
|
*
|
||||||
|
* @param player the player
|
||||||
|
* @param dirStr the direction string
|
||||||
|
* @return a direction vector
|
||||||
|
* @throws UnknownDirectionException thrown if the direction is not known
|
||||||
|
*/
|
||||||
|
public BlockVector3 getDiagonalDirection(Player player, String dirStr) throws UnknownDirectionException {
|
||||||
|
dirStr = dirStr.toLowerCase();
|
||||||
|
|
||||||
|
final Direction dir = getPlayerDirection(player, dirStr);
|
||||||
|
|
||||||
|
if (dir.isCardinal() || dir.isOrdinal() || dir.isUpright()) {
|
||||||
|
return dir.toBlockVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnknownDirectionException(dir.name());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the direction vector for a player's direction. May return
|
* Get the direction vector for a player's direction. May return
|
||||||
* null if a direction could not be found.
|
* null if a direction could not be found.
|
||||||
@ -399,46 +414,46 @@ public class WorldEdit {
|
|||||||
* @return a direction enum value
|
* @return a direction enum value
|
||||||
* @throws UnknownDirectionException thrown if the direction is not known
|
* @throws UnknownDirectionException thrown if the direction is not known
|
||||||
*/
|
*/
|
||||||
private PlayerDirection getPlayerDirection(Player player, String dirStr) throws UnknownDirectionException {
|
private Direction getPlayerDirection(Player player, String dirStr) throws UnknownDirectionException {
|
||||||
final PlayerDirection dir;
|
final Direction dir;
|
||||||
|
|
||||||
switch (dirStr.charAt(0)) {
|
switch (dirStr.charAt(0)) {
|
||||||
case 'w':
|
case 'w':
|
||||||
dir = PlayerDirection.WEST;
|
dir = Direction.WEST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
dir = PlayerDirection.EAST;
|
dir = Direction.EAST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if (dirStr.indexOf('w') > 0) {
|
if (dirStr.indexOf('w') > 0) {
|
||||||
return PlayerDirection.SOUTH_WEST;
|
return Direction.SOUTHWEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirStr.indexOf('e') > 0) {
|
if (dirStr.indexOf('e') > 0) {
|
||||||
return PlayerDirection.SOUTH_EAST;
|
return Direction.SOUTHEAST;
|
||||||
}
|
}
|
||||||
dir = PlayerDirection.SOUTH;
|
dir = Direction.SOUTH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
if (dirStr.indexOf('w') > 0) {
|
if (dirStr.indexOf('w') > 0) {
|
||||||
return PlayerDirection.NORTH_WEST;
|
return Direction.NORTHWEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirStr.indexOf('e') > 0) {
|
if (dirStr.indexOf('e') > 0) {
|
||||||
return PlayerDirection.NORTH_EAST;
|
return Direction.NORTHEAST;
|
||||||
}
|
}
|
||||||
dir = PlayerDirection.NORTH;
|
dir = Direction.NORTH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
dir = PlayerDirection.UP;
|
dir = Direction.UP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
dir = PlayerDirection.DOWN;
|
dir = Direction.DOWN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm': // me
|
case 'm': // me
|
||||||
|
@ -275,7 +275,7 @@ public class RegionCommands {
|
|||||||
public void move(Player player, EditSession editSession, LocalSession session,
|
public void move(Player player, EditSession editSession, LocalSession session,
|
||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Optional("1") @Range(min = 1) int count,
|
@Optional("1") @Range(min = 1) int count,
|
||||||
@Optional(Direction.AIM) @Direction BlockVector3 direction,
|
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction,
|
||||||
@Optional("air") BlockStateHolder replace,
|
@Optional("air") BlockStateHolder replace,
|
||||||
@Switch('s') boolean moveSelection) throws WorldEditException {
|
@Switch('s') boolean moveSelection) throws WorldEditException {
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ public class RegionCommands {
|
|||||||
public void stack(Player player, EditSession editSession, LocalSession session,
|
public void stack(Player player, EditSession editSession, LocalSession session,
|
||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Optional("1") @Range(min = 1) int count,
|
@Optional("1") @Range(min = 1) int count,
|
||||||
@Optional(Direction.AIM) @Direction BlockVector3 direction,
|
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction,
|
||||||
@Switch('s') boolean moveSelection,
|
@Switch('s') boolean moveSelection,
|
||||||
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException {
|
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException {
|
||||||
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks);
|
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks);
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.entity;
|
package com.sk89q.worldedit.entity;
|
||||||
|
|
||||||
import com.sk89q.worldedit.PlayerDirection;
|
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
@ -60,7 +60,7 @@ public interface Player extends Entity, Actor {
|
|||||||
*
|
*
|
||||||
* @return the direction
|
* @return the direction
|
||||||
*/
|
*/
|
||||||
PlayerDirection getCardinalDirection(int yawOffset);
|
Direction getCardinalDirection(int yawOffset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the item that the player is holding.
|
* Get the item that the player is holding.
|
||||||
@ -240,7 +240,7 @@ public interface Player extends Entity, Actor {
|
|||||||
*
|
*
|
||||||
* @return the direction
|
* @return the direction
|
||||||
*/
|
*/
|
||||||
PlayerDirection getCardinalDirection();
|
Direction getCardinalDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass through the wall that you are looking at.
|
* Pass through the wall that you are looking at.
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
package com.sk89q.worldedit.extension.platform;
|
package com.sk89q.worldedit.extension.platform;
|
||||||
|
|
||||||
import com.sk89q.worldedit.NotABlockException;
|
import com.sk89q.worldedit.NotABlockException;
|
||||||
import com.sk89q.worldedit.PlayerDirection;
|
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.util.TargetBlock;
|
import com.sk89q.worldedit.util.TargetBlock;
|
||||||
@ -61,25 +61,25 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
|||||||
* @param rot yaw
|
* @param rot yaw
|
||||||
* @return the direction
|
* @return the direction
|
||||||
*/
|
*/
|
||||||
private static PlayerDirection getDirection(double rot) {
|
private static Direction getDirection(double rot) {
|
||||||
if (0 <= rot && rot < 22.5) {
|
if (0 <= rot && rot < 22.5) {
|
||||||
return PlayerDirection.SOUTH;
|
return Direction.SOUTH;
|
||||||
} else if (22.5 <= rot && rot < 67.5) {
|
} else if (22.5 <= rot && rot < 67.5) {
|
||||||
return PlayerDirection.SOUTH_WEST;
|
return Direction.SOUTHWEST;
|
||||||
} else if (67.5 <= rot && rot < 112.5) {
|
} else if (67.5 <= rot && rot < 112.5) {
|
||||||
return PlayerDirection.WEST;
|
return Direction.WEST;
|
||||||
} else if (112.5 <= rot && rot < 157.5) {
|
} else if (112.5 <= rot && rot < 157.5) {
|
||||||
return PlayerDirection.NORTH_WEST;
|
return Direction.NORTHWEST;
|
||||||
} else if (157.5 <= rot && rot < 202.5) {
|
} else if (157.5 <= rot && rot < 202.5) {
|
||||||
return PlayerDirection.NORTH;
|
return Direction.NORTH;
|
||||||
} else if (202.5 <= rot && rot < 247.5) {
|
} else if (202.5 <= rot && rot < 247.5) {
|
||||||
return PlayerDirection.NORTH_EAST;
|
return Direction.NORTHEAST;
|
||||||
} else if (247.5 <= rot && rot < 292.5) {
|
} else if (247.5 <= rot && rot < 292.5) {
|
||||||
return PlayerDirection.EAST;
|
return Direction.EAST;
|
||||||
} else if (292.5 <= rot && rot < 337.5) {
|
} else if (292.5 <= rot && rot < 337.5) {
|
||||||
return PlayerDirection.SOUTH_EAST;
|
return Direction.SOUTHEAST;
|
||||||
} else if (337.5 <= rot && rot < 360.0) {
|
} else if (337.5 <= rot && rot < 360.0) {
|
||||||
return PlayerDirection.SOUTH;
|
return Direction.SOUTH;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -345,17 +345,17 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDirection getCardinalDirection() {
|
public Direction getCardinalDirection() {
|
||||||
return getCardinalDirection(0);
|
return getCardinalDirection(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDirection getCardinalDirection(int yawOffset) {
|
public Direction getCardinalDirection(int yawOffset) {
|
||||||
if (getLocation().getPitch() > 67.5) {
|
if (getLocation().getPitch() > 67.5) {
|
||||||
return PlayerDirection.DOWN;
|
return Direction.DOWN;
|
||||||
}
|
}
|
||||||
if (getLocation().getPitch() < -67.5) {
|
if (getLocation().getPitch() < -67.5) {
|
||||||
return PlayerDirection.UP;
|
return Direction.UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
// From hey0's code
|
// From hey0's code
|
||||||
|
@ -35,4 +35,5 @@ public @interface Direction {
|
|||||||
|
|
||||||
String AIM = "me";
|
String AIM = "me";
|
||||||
|
|
||||||
|
boolean includeDiagonals() default false;
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,12 @@ public class WorldEditBinding extends BindingHelper {
|
|||||||
public BlockVector3 getDirection(ArgumentStack context, Direction direction)
|
public BlockVector3 getDirection(ArgumentStack context, Direction direction)
|
||||||
throws ParameterException, UnknownDirectionException {
|
throws ParameterException, UnknownDirectionException {
|
||||||
Player sender = getPlayer(context);
|
Player sender = getPlayer(context);
|
||||||
|
if (direction.includeDiagonals()) {
|
||||||
|
return worldEdit.getDiagonalDirection(sender, context.next());
|
||||||
|
} else {
|
||||||
return worldEdit.getDirection(sender, context.next());
|
return worldEdit.getDirection(sender, context.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an {@link TreeType} from a {@link ArgumentStack}.
|
* Gets an {@link TreeType} from a {@link ArgumentStack}.
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren