Skip to content
Permalink
Browse files

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).
  • Loading branch information...
wizjany committed Jul 10, 2019
1 parent 05cee0a commit 0627e936dc9e4a8e9ee7451b76e30d3331bbb3fa
@@ -180,7 +180,8 @@ public void setBiome(Player player, LocalSession session, EditSession editSessio
Mask2D mask2d = mask != null ? mask.toMask2D() : null;

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 {
region = session.getSelection(world);
}
@@ -19,7 +19,10 @@

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.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
@@ -32,6 +35,7 @@
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock;
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.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@@ -173,7 +177,7 @@ public boolean ascendLevel() {
if (spots == 2) {
final BlockVector3 platform = BlockVector3.at(x, y - 2, z);
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!
if (type == BlockTypes.LAVA) {
@@ -259,6 +263,13 @@ public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
// Found a ceiling!
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) {
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);
return true;
}
@@ -302,25 +313,27 @@ public boolean ascendUpwards(int distance, boolean alwaysGlass) {

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try {
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState());
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
final World world = (World) getLocation().getExtent();
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
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));
}

@Override
public Location getBlockIn() {
return getLocation().setPosition(getLocation().toVector().floor());
final Location location = getLocation();
return location.setPosition(location.toVector().floor());
}

@Override
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
@@ -369,15 +382,16 @@ public Direction getCardinalDirection() {

@Override
public Direction getCardinalDirection(int yawOffset) {
if (getLocation().getPitch() > 67.5) {
final Location location = getLocation();
if (location.getPitch() > 67.5) {
return Direction.DOWN;
}
if (getLocation().getPitch() < -67.5) {
if (location.getPitch() < -67.5) {
return Direction.UP;
}

// 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) {
rot += 360.0;
}
@@ -446,7 +460,8 @@ public boolean passThroughForwardWall(int range) {

@Override
public void setPosition(Vector3 pos) {
setPosition(pos, getLocation().getPitch(), getLocation().getYaw());
final Location location = getLocation();
setPosition(pos, location.getPitch(), location.getYaw());
}

@Override
@@ -178,4 +178,9 @@ public void setGameMode(GameMode gameMode) {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
basePlayer.sendFakeBlock(pos, block);
}

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
basePlayer.floatAt(x, y, z, alwaysGlass);
}
}
@@ -260,8 +260,9 @@ private void writeEntities(Clipboard clipboard, Map<String, Tag> schematic) {
}
values.remove("id");
values.put("Id", new StringTag(state.getType().getId()));
values.put("Pos", writeVector(e.getLocation().toVector()));
values.put("Rotation", writeRotation(e.getLocation()));
final Location location = e.getLocation();
values.put("Pos", writeVector(location.toVector()));
values.put("Rotation", writeRotation(location));

return new CompoundTag(values);
}).filter(Objects::nonNull).collect(Collectors.toList());
@@ -32,6 +32,7 @@
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
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.BlockTypes;

@@ -114,11 +115,12 @@ public static BaseBlock createStructureBlock(Player player) {
}

// Borrowed this math from FAWE
double rotX = player.getLocation().getYaw();
double rotY = player.getLocation().getPitch();
final Location location = player.getLocation();
double rotX = location.getYaw();
double rotY = location.getPitch();
double xz = Math.cos(Math.toRadians(rotY));
int x = (int) (player.getLocation().getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12);
int z = (int) (player.getLocation().getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12);
int x = (int) (location.getX() - (-xz * Math.sin(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));

Map<String, Tag> structureTag = new HashMap<>();
@@ -106,7 +106,7 @@ public boolean setLocation(Location location) {
}

@Override
public com.sk89q.worldedit.world.World getWorld() {
public World getWorld() {
return FabricWorldEdit.inst.getWorld(this.player.world);
}

@@ -188,6 +188,20 @@ public boolean hasPermission(String perm) {
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
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld();
@@ -107,7 +107,7 @@ public boolean setLocation(Location location) {
}

@Override
public com.sk89q.worldedit.world.World getWorld() {
public World getWorld() {
return ForgeWorldEdit.inst.getWorld(this.player.world);
}

@@ -189,6 +189,20 @@ public boolean hasPermission(String perm) {
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
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld();
@@ -38,6 +38,7 @@
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.ItemType;
@@ -202,6 +203,17 @@ public void setGameMode(GameMode gameMode) {
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
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());

0 comments on commit 0627e93

Please sign in to comment.
You can’t perform that action at this time.