Cleanup/fix ascend logic

Fixes #1419
This commit is contained in:
Octavia Togami 2020-07-03 20:17:30 -07:00
parent 8c171f0929
commit cc46de951b
No known key found for this signature in database
GPG Key ID: CC364524D1983C99

View File

@ -38,6 +38,7 @@
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
@ -172,9 +173,14 @@ public void findFreePosition() {
findFreePosition(getBlockLocation());
}
private boolean isBadSpaceForStanding(BlockVector3 location) {
/**
* Determines if the block at the given location "harms" the player, either by suffocation
* or other means.
*/
private boolean isPlayerHarmingBlock(BlockVector3 location) {
BlockType type = getWorld().getBlock(location).getBlockType();
return type.getMaterial().isMovementBlocker() || type == BlockTypes.LAVA;
return type.getMaterial().isMovementBlocker() || type == BlockTypes.LAVA
|| BlockCategories.FIRE.contains(type);
}
/**
@ -182,10 +188,10 @@ private boolean isBadSpaceForStanding(BlockVector3 location) {
* @return if the player can stand at the location
*/
private boolean isLocationGoodForStanding(BlockVector3 location) {
if (isBadSpaceForStanding(location.add(0, 1, 0))) {
if (isPlayerHarmingBlock(location.add(0, 1, 0))) {
return false;
}
if (isBadSpaceForStanding(location)) {
if (isPlayerHarmingBlock(location)) {
return false;
}
return getWorld().getBlock(location.add(0, -1, 0)).getBlockType().getMaterial()
@ -197,7 +203,7 @@ public boolean ascendLevel() {
final World world = getWorld();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
int y = Math.max(world.getMinY(), pos.getBlockY());
int y = Math.max(world.getMinY(), pos.getBlockY() + 1);
final int z = pos.getBlockZ();
int yPlusSearchHeight = y + WorldEdit.getInstance().getConfiguration().defaultVerticalHeight;
int maxY = Math.min(world.getMaxY(), yPlusSearchHeight) + 2;