From 911d3a00eb4422b59aaebf47cd777f14331620eb Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Fri, 9 Apr 2021 22:59:31 +0200 Subject: [PATCH] Don't paste biomes out of bounds, fix #1009 Also some preparations for variable world heights --- .../java/com/sk89q/worldedit/EditSession.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 0fb662709..3b8c3cc10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -223,6 +223,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { private final Extent bypassHistory; private Extent bypassAll; + private final int minY; private final int maxY; private final List watchdogExtents = new ArrayList<>(2); @@ -263,6 +264,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { this.limit = builder.getLimit().copy(); this.player = builder.getPlayer(); this.changeSet = builder.getChangeTask(); + this.minY = world.getMinY(); this.maxY = world.getMaxY(); this.blockBag = builder.getBlockBag(); this.history = changeSet != null; @@ -796,12 +798,18 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override public boolean setBiome(BlockVector3 position, BiomeType biome) { + if (position.getY() < this.minY || position.getY() > this.maxY) { + return false; + } this.changes++; return this.getExtent().setBiome(position, biome); } @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + if (y < this.minY || y > this.maxY) { + return false; + } this.changes++; return this.getExtent().setBiome(x, y, z, biome); } @@ -859,7 +867,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { */ @Deprecated public > boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException { - if (position.getBlockY() < 0 || position.getBlockY() > 255) { + if (position.getBlockY() < this.minY || position.getBlockY() > this.maxY) { return false; } @@ -885,7 +893,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { */ @Deprecated public > boolean rawSetBlock(BlockVector3 position, B block) { - if (position.getBlockY() < 0 || position.getBlockY() > 255) { + if (position.getBlockY() < this.minY || position.getBlockY() > this.maxY) { return false; } @@ -905,7 +913,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @return whether the block changed */ public > boolean smartSetBlock(BlockVector3 position, B block) { - if (position.getBlockY() < 0 || position.getBlockY() > 255) { + if (position.getBlockY() < this.minY || position.getBlockY() > this.maxY) { return false; } @@ -920,7 +928,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override @Deprecated public > boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException { - if (position.getBlockY() < 0 || position.getBlockY() > 255) { + if (position.getBlockY() < this.minY || position.getBlockY() > this.maxY) { return false; } @@ -937,7 +945,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override public > boolean setBlock(int x, int y, int z, B block) { - if (y < 0 || y > 255) { + if (y < this.minY || y > this.maxY) { return false; } @@ -960,7 +968,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public boolean setBlock(int x, int y, int z, Pattern pattern) { - if (y < 0 || y > 255) { + if (y < this.minY || y > this.maxY) { return false; } @@ -982,7 +990,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException { - if (position.getBlockY() < 0 || position.getBlockY() > 255) { + if (position.getBlockY() < this.minY || position.getBlockY() > this.maxY) { return false; }