From 98bd93c752a320fbbad701ad780f118619e751d6 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 17 Feb 2020 17:00:29 -0500 Subject: [PATCH] Clamp Y coordinates during selection --- .../visualization/ImmutableVirtualWorld.java | 4 ++-- .../brush/visualization/VirtualWorld.java | 2 +- .../cfi/HeightMapMCAGenerator.java | 8 ++++---- .../worldedit/command/SelectionCommands.java | 20 +++++++++---------- .../extension/platform/PlatformManager.java | 2 -- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java index 3c33bd6d0..2344a118e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java @@ -37,7 +37,7 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException { return setBlock(position, block); } @@ -72,7 +72,7 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { } @Override - public boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 pt, B block) throws WorldEditException { return unsupported(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java index 8f8cd35e1..884afea68 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java @@ -25,7 +25,7 @@ public interface VirtualWorld extends SimpleWorld, Closeable { int getMaxY(); @Override - boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException; + > boolean setBlock(BlockVector3 pt, B block) throws WorldEditException; Player getPlayer(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index 460ce7402..7e2213904 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java @@ -718,7 +718,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { return setBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ(), block); } @@ -951,7 +951,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { return this.setBlock(x, y, z, block.getOrdinalChar()); } @@ -979,7 +979,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr return heights.getByte(index) & 0xFF; } - public void setFloor(int x, int z, BlockStateHolder block) { + public > void setFloor(int x, int z, B block) { int index = z * getWidth() + x; floor.setInt(index, block.getOrdinalChar()); } @@ -1914,7 +1914,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException { return setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index d42d27c27..807a4a568 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -120,9 +120,9 @@ public class SelectionCommands { BlockVector3 coordinates) throws WorldEditException { Location pos; if (coordinates != null) { - pos = new Location(world, coordinates.toVector3()); + pos = new Location(world, coordinates.toVector3().clampY(0, world.getMaxY())); } else if (actor instanceof Locatable) { - pos = ((Locatable) actor).getBlockLocation(); + pos = ((Locatable) actor).getBlockLocation().clampY(0, world.getMaxY()); } else { actor.printError(TranslatableComponent.of("worldedit.pos.console-require-coords")); return; @@ -149,9 +149,9 @@ public class SelectionCommands { BlockVector3 coordinates) throws WorldEditException { Location pos; if (coordinates != null) { - pos = new Location(world, coordinates.toVector3()); + pos = new Location(world, coordinates.toVector3().clampY(0, world.getMaxY())); } else if (actor instanceof Locatable) { - pos = ((Locatable) actor).getBlockLocation(); + pos = ((Locatable) actor).getBlockLocation().clampY(0, world.getMaxY()); } else { actor.printError(TranslatableComponent.of("worldedit.pos.console-require-coords")); return; @@ -523,16 +523,14 @@ public class SelectionCommands { @CommandPermissions("worldedit.analysis.distr") public void distr(Actor actor, World world, LocalSession session, @Switch(name = 'c', desc = "Get the distribution of the clipboard instead") - boolean clipboardDistr, + boolean clipboardDistr, @Switch(name = 'd', desc = "Separate blocks by state") - boolean separateStates, + boolean separateStates, @ArgFlag(name = 'p', desc = "Gets page from a previous distribution.", def = "") - Integer page) throws WorldEditException { + Integer page) throws WorldEditException { List> distribution; - Region region; if (page == null) { - Extent extent; if (clipboardDistr) { Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates); @@ -541,8 +539,7 @@ public class SelectionCommands { distribution = count.getDistribution(); } else { try (EditSession editSession = session.createEditSession(actor)) { - distribution = editSession - .getBlockDistribution(session.getSelection(world), separateStates); + distribution = editSession.getBlockDistribution(session.getSelection(world), separateStates); } } session.setLastDistribution(distribution); @@ -554,6 +551,7 @@ public class SelectionCommands { return; } } + if (distribution.isEmpty()) { // *Should* always be false actor.printError(TranslatableComponent.of("worldedit.distr.no-blocks")); return; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 431711d07..9bd3acbc1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -406,7 +406,6 @@ public class PlatformManager { // making changes to the world Player player = createProxyActor(event.getPlayer()); LocalSession session = worldEdit.getSessionManager().get(player); - VirtualWorld virtual = session.getVirtualWorld(); if (virtual != null) { virtual.handlePlayerInput(player, event); @@ -416,7 +415,6 @@ public class PlatformManager { try { switch (event.getInputType()) { case PRIMARY: { - Tool tool = session.getTool(player); if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) { player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING),