Fix error in /up when used out of bounds.

Also reduce calls to Entity#getLocation() all over since it's
more expensive than it needs to be (adapts world/vector every time).
Dieser Commit ist enthalten in:
wizjany 2019-07-10 18:25:34 -04:00
Ursprung e504c29df6
Commit 8545417b3a
8 geänderte Dateien mit 86 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -180,7 +180,8 @@ public class BiomeCommands {
Mask2D mask2d = mask != null ? mask.toMask2D() : null; Mask2D mask2d = mask != null ? mask.toMask2D() : null;
if (atPosition) { if (atPosition) {
region = new CuboidRegion(player.getLocation().toVector().toBlockPoint(), player.getLocation().toVector().toBlockPoint()); final BlockVector3 pos = player.getLocation().toVector().toBlockPoint();
region = new CuboidRegion(pos, pos);
} else { } else {
region = session.getSelection(world); region = session.getSelection(world);
} }

Datei anzeigen

@ -19,7 +19,10 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
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;
@ -32,6 +35,7 @@ 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;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -173,7 +177,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (spots == 2) { if (spots == 2) {
final BlockVector3 platform = BlockVector3.at(x, y - 2, z); final BlockVector3 platform = BlockVector3.at(x, y - 2, z);
final BlockState block = world.getBlock(platform); final BlockState block = world.getBlock(platform);
final com.sk89q.worldedit.world.block.BlockType type = block.getBlockType(); final BlockType type = block.getBlockType();
// Don't get put in lava! // Don't get put in lava!
if (type == BlockTypes.LAVA) { if (type == BlockTypes.LAVA) {
@ -259,6 +263,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
// Found a ceiling! // Found a ceiling!
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
int platformY = Math.max(initialY, y - 3 - clearance); int platformY = Math.max(initialY, y - 3 - clearance);
if (platformY < initialY) { // if ==, they already have the given clearance, if <, clearance is too large
printError("Not enough space above you!");
return false;
} else if (platformY == initialY) {
printError("You're already at the ceiling.");
return false;
}
floatAt(x, platformY + 1, z, alwaysGlass); floatAt(x, platformY + 1, z, alwaysGlass);
return true; return true;
} }
@ -302,25 +313,27 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) { public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try { BlockVector3 spot = BlockVector3.at(x, y - 1, z);
BlockVector3 spot = BlockVector3.at(x, y - 1, z); final World world = (World) getLocation().getExtent();
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
} }
} catch (WorldEditException e) {
e.printStackTrace();
} }
setPosition(Vector3.at(x + 0.5, y, z + 0.5)); setPosition(Vector3.at(x + 0.5, y, z + 0.5));
} }
@Override @Override
public Location getBlockIn() { public Location getBlockIn() {
return getLocation().setPosition(getLocation().toVector().floor()); final Location location = getLocation();
return location.setPosition(location.toVector().floor());
} }
@Override @Override
public Location getBlockOn() { public Location getBlockOn() {
return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor()); final Location location = getLocation();
return location.setPosition(location.setY(location.getY() - 1).toVector().floor());
} }
@Override @Override
@ -369,15 +382,16 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public Direction getCardinalDirection(int yawOffset) { public Direction getCardinalDirection(int yawOffset) {
if (getLocation().getPitch() > 67.5) { final Location location = getLocation();
if (location.getPitch() > 67.5) {
return Direction.DOWN; return Direction.DOWN;
} }
if (getLocation().getPitch() < -67.5) { if (location.getPitch() < -67.5) {
return Direction.UP; return Direction.UP;
} }
// From hey0's code // From hey0's code
double rot = (getLocation().getYaw() + yawOffset) % 360; //let's use real yaw now double rot = (location.getYaw() + yawOffset) % 360; //let's use real yaw now
if (rot < 0) { if (rot < 0) {
rot += 360.0; rot += 360.0;
} }
@ -446,7 +460,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override @Override
public void setPosition(Vector3 pos) { public void setPosition(Vector3 pos) {
setPosition(pos, getLocation().getPitch(), getLocation().getYaw()); final Location location = getLocation();
setPosition(pos, location.getPitch(), location.getYaw());
} }
@Override @Override

Datei anzeigen

@ -178,4 +178,9 @@ class PlayerProxy extends AbstractPlayerActor {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
basePlayer.sendFakeBlock(pos, block); basePlayer.sendFakeBlock(pos, block);
} }
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
basePlayer.floatAt(x, y, z, alwaysGlass);
}
} }

Datei anzeigen

@ -260,8 +260,9 @@ public class SpongeSchematicWriter implements ClipboardWriter {
} }
values.remove("id"); values.remove("id");
values.put("Id", new StringTag(state.getType().getId())); values.put("Id", new StringTag(state.getType().getId()));
values.put("Pos", writeVector(e.getLocation().toVector())); final Location location = e.getLocation();
values.put("Rotation", writeRotation(e.getLocation())); values.put("Pos", writeVector(location.toVector()));
values.put("Rotation", writeRotation(location));
return new CompoundTag(values); return new CompoundTag(values);
}).filter(Objects::nonNull).collect(Collectors.toList()); }).filter(Objects::nonNull).collect(Collectors.toList());

Datei anzeigen

@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -114,11 +115,12 @@ public class ServerCUIHandler {
} }
// Borrowed this math from FAWE // Borrowed this math from FAWE
double rotX = player.getLocation().getYaw(); final Location location = player.getLocation();
double rotY = player.getLocation().getPitch(); double rotX = location.getYaw();
double rotY = location.getPitch();
double xz = Math.cos(Math.toRadians(rotY)); double xz = Math.cos(Math.toRadians(rotY));
int x = (int) (player.getLocation().getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12); int x = (int) (location.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12);
int z = (int) (player.getLocation().getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12); int z = (int) (location.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12);
int y = Math.max(0, Math.min(Math.min(255, posY + 32), posY + 3)); int y = Math.max(0, Math.min(Math.min(255, posY + 32), posY + 3));
Map<String, Tag> structureTag = new HashMap<>(); Map<String, Tag> structureTag = new HashMap<>();

Datei anzeigen

@ -106,7 +106,7 @@ public class FabricPlayer extends AbstractPlayerActor {
} }
@Override @Override
public com.sk89q.worldedit.world.World getWorld() { public World getWorld() {
return FabricWorldEdit.inst.getWorld(this.player.world); return FabricWorldEdit.inst.getWorld(this.player.world);
} }
@ -188,6 +188,20 @@ public class FabricPlayer extends AbstractPlayerActor {
return null; return null;
} }
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.abilities.allowFlying) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
if (!player.abilities.flying) {
player.abilities.flying = true;
player.sendAbilitiesUpdate();
}
}
@Override @Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld(); World world = getWorld();

Datei anzeigen

@ -107,7 +107,7 @@ public class ForgePlayer extends AbstractPlayerActor {
} }
@Override @Override
public com.sk89q.worldedit.world.World getWorld() { public World getWorld() {
return ForgeWorldEdit.inst.getWorld(this.player.world); return ForgeWorldEdit.inst.getWorld(this.player.world);
} }
@ -189,6 +189,20 @@ public class ForgePlayer extends AbstractPlayerActor {
return null; return null;
} }
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.abilities.allowFlying) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
if (!player.abilities.isFlying) {
player.abilities.isFlying = true;
player.sendPlayerAbilities();
}
}
@Override @Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld(); World world = getWorld();

Datei anzeigen

@ -38,6 +38,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.ItemType;
@ -202,6 +203,17 @@ public class SpongePlayer extends AbstractPlayerActor {
gameMode.getId()).get()); gameMode.getId()).get());
} }
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.get(Keys.CAN_FLY).orElse(false)) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.offer(Keys.IS_FLYING, true);
}
@Override @Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
org.spongepowered.api.world.Location<World> loc = player.getWorld().getLocation(pos.getX(), pos.getY(), pos.getZ()); org.spongepowered.api.world.Location<World> loc = player.getWorld().getLocation(pos.getX(), pos.getY(), pos.getZ());