From 07ea1bc9c74b14594d7d390b7b54ed40e810abfd Mon Sep 17 00:00:00 2001 From: Spencer Date: Sat, 25 Nov 2017 15:23:29 -0500 Subject: [PATCH] Set BL/TR corners inside BuildData --- .../game/arcade/game/games/build/Build.java | 26 ++---- .../arcade/game/games/build/BuildData.java | 89 +++++++++++++------ 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java index 42a5cdca5..6e1517b68 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java @@ -746,36 +746,24 @@ public class Build extends Game public void teleportPlayers(BuildData data) { - Location lowestLoc; - Location highestLoc; - - // Find the lowest corner by comparing y-values - if (data.CornerA.getY() < data.CornerB.getY()) { - lowestLoc = data.CornerA; - highestLoc = data.CornerB; - } else { - lowestLoc = data.CornerB; - highestLoc = data.CornerA; - } - // We're going to expand the boundaries of the corners // by some number of blocks which will give us a square // to teleport players on the edge of. - Location expandedBottomLeft = lowestLoc.clone(); - Location expandedTopRight = highestLoc.clone(); + Location expandedBottomLeft = data.CornerBottomLeft.clone(); + Location expandedTopRight = data.CornerTopRight.clone(); // Move the corners to the same Y-Level - expandedTopRight.setY(lowestLoc.getY()); + expandedTopRight.setY(data.CornerBottomLeft.getY()); // Set the x of bottom left and top right to be left/right // respectively... - expandedBottomLeft.setX(Math.min(lowestLoc.getX(), highestLoc.getX()) - TELEPORT_BORDER_DISTANCE); - expandedTopRight.setX(Math.max(lowestLoc.getX(), highestLoc.getX()) + TELEPORT_BORDER_DISTANCE); + expandedBottomLeft.setX(data.CornerBottomLeft.getX() - TELEPORT_BORDER_DISTANCE); + expandedTopRight.setX(data.CornerTopRight.getX() + TELEPORT_BORDER_DISTANCE); // Set the z of bottom left and top right to be bottom/top // respectively... - expandedBottomLeft.setZ(Math.min(lowestLoc.getZ(), highestLoc.getZ()) - TELEPORT_BORDER_DISTANCE); - expandedTopRight.setZ(Math.max(lowestLoc.getZ(), highestLoc.getZ()) + TELEPORT_BORDER_DISTANCE); + expandedBottomLeft.setZ(data.CornerBottomLeft.getZ() - TELEPORT_BORDER_DISTANCE); + expandedTopRight.setZ(data.CornerBottomLeft.getZ() + TELEPORT_BORDER_DISTANCE); // Now that we have the two corners of the square, get a list with all // the locations for the square's edge. diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/BuildData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/BuildData.java index 6296e4bc9..cea7e01c3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/BuildData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/BuildData.java @@ -54,8 +54,8 @@ public class BuildData public Location Spawn; - public Location CornerA; - public Location CornerB; + public Location CornerBottomLeft; + public Location CornerTopRight; public HashSet Blocks = new HashSet(); @@ -85,10 +85,12 @@ public class BuildData { this(player, spawn); - CornerA = UtilAlg.findClosest(spawn, buildBorders); + Location CornerA = UtilAlg.findClosest(spawn, buildBorders); buildBorders.remove(CornerA); - CornerB = UtilAlg.findClosest(spawn, buildBorders); + Location CornerB = UtilAlg.findClosest(spawn, buildBorders); buildBorders.remove(CornerB); + + setCorners(CornerA, CornerB); } public BuildData(GameTeam team, Location spawn, ArrayList buildBorders) @@ -97,10 +99,43 @@ public class BuildData Team = team; Spawn = spawn; - CornerA = UtilAlg.findClosest(spawn, buildBorders); + Location CornerA = UtilAlg.findClosest(spawn, buildBorders); buildBorders.remove(CornerA); - CornerB = UtilAlg.findClosest(spawn, buildBorders); + Location CornerB = UtilAlg.findClosest(spawn, buildBorders); buildBorders.remove(CornerB); + + setCorners(CornerA, CornerB); + } + + /** + * Normalizes corners by setting + * CornerBottomLeft to be the "bottom-left" + * corner (lowest y-value, lowest x, and + * lowest z) and CornerTopRight to be the + * "top-right" corner (highest y-value, + * highest x, and highest z) + */ + private void setCorners(Location CornerA, Location CornerB) { + Location bottomLeft; + Location topRight; + + // Find the lowest corner by comparing y-values + if (CornerA.getY() < CornerB.getY()) { + bottomLeft = CornerA.clone(); + topRight = CornerB.clone(); + } else { + bottomLeft = CornerB.clone(); + topRight = CornerA.clone(); + } + + bottomLeft.setX(Math.min(CornerA.getX(), CornerB.getX())); + topRight.setX(Math.max(CornerA.getX(), CornerB.getX())); + + bottomLeft.setZ(Math.min(CornerA.getZ(), CornerB.getZ())); + topRight.setZ(Math.min(CornerA.getZ(), CornerB.getZ())); + + CornerBottomLeft = bottomLeft; + CornerTopRight = topRight; } public boolean addItem(Item item) @@ -219,27 +254,27 @@ public class BuildData { if (!block.getWorld().getName().equals(Spawn.getWorld().getName())) return false; - return inBuildArea(block.getLocation().add(0.5, 0, 0.5).toVector()); + return inBuildArea(block.getLocation().toVector()); } - public boolean inBuildArea(Vector vec) + public boolean inBuildArea(Vector vec) { - if (vec.getX() < Math.min(CornerA.getBlockX(), CornerB.getBlockX())) + if (vec.getBlockX() <= CornerBottomLeft.getBlockX()) return false; - if (vec.getY() < Math.min(CornerA.getBlockY(), CornerB.getBlockY())) + if (vec.getBlockY() < CornerBottomLeft.getBlockY()) return false; - if (vec.getZ() < Math.min(CornerA.getBlockZ(), CornerB.getBlockZ())) + if (vec.getBlockZ() < CornerBottomLeft.getBlockZ()) return false; - if (vec.getX() > Math.max(CornerA.getBlockX(), CornerB.getBlockX())) + if (vec.getBlockX() > CornerTopRight.getBlockX()) return false; - if (vec.getY() > Math.max(CornerA.getBlockY(), CornerB.getBlockY())) + if (vec.getBlockY() > CornerTopRight.getBlockY()) return false; - if (vec.getZ() > Math.max(CornerA.getBlockZ(), CornerB.getBlockZ())) + if (vec.getBlockZ() > CornerTopRight.getBlockZ()) return false; return true; @@ -391,29 +426,29 @@ public class BuildData //Set everything to air first to prevent the forming of obby. if (mat == Material.LAVA || mat == Material.WATER) { - int y = Math.min(CornerA.getBlockY(), CornerB.getBlockY()) - 1; - for (int x= Math.min(CornerA.getBlockX(), CornerB.getBlockX()) ; x <= Math.max(CornerA.getBlockX(), CornerB.getBlockX()) ; x++) + int y = CornerBottomLeft.getBlockY() - 1; + for (int x = CornerBottomLeft.getBlockX(); x <= CornerTopRight.getBlockX(); x++) { - for (int z= Math.min(CornerA.getBlockZ(), CornerB.getBlockZ()) ; z <= Math.max(CornerA.getBlockZ(), CornerB.getBlockZ()) ; z++) + for (int z = CornerBottomLeft.getBlockZ(); z <= CornerTopRight.getBlockZ(); z++) { MapUtil.QuickChangeBlockAt(player.getWorld(), x, y, z, Material.AIR, data); } } } - int x = Math.min(CornerA.getBlockX(), CornerB.getBlockX()); - int y = Math.min(CornerA.getBlockY(), CornerB.getBlockY()) - 1; - int z = Math.min(CornerA.getBlockZ(), CornerB.getBlockZ()); + int x = CornerBottomLeft.getBlockX(); + int y = CornerBottomLeft.getBlockY() - 1; + int z = CornerBottomLeft.getBlockZ(); if (ground.hasSchematic()) { - ground.getSchematic().paste(new Location(CornerA.getWorld(), x, y, z), true); + ground.getSchematic().paste(new Location(CornerBottomLeft.getWorld(), x, y, z), true); return; } - for (int dx = x; dx <= Math.max(CornerA.getBlockX(), CornerB.getBlockX()) ; dx++) + for (int dx = x; dx <= CornerTopRight.getBlockX(); dx++) { - for (int dz = z; dz <= Math.max(CornerA.getBlockZ(), CornerB.getBlockZ()) ; dz++) + for (int dz = z; dz <= CornerTopRight.getBlockZ(); dz++) { MapUtil.QuickChangeBlockAt(player.getWorld(), dx, y, dz, mat, data); } @@ -437,22 +472,22 @@ public class BuildData protected Location getMin() { - return Vector.getMinimum(CornerA.toVector(), CornerB.toVector()).toBlockVector().toLocation(CornerA.getWorld()).subtract(0, 1, 0); + return Vector.getMinimum(CornerBottomLeft.toVector(), CornerTopRight.toVector()).toBlockVector().toLocation(CornerBottomLeft.getWorld()).subtract(0, 1, 0); } protected Location getMax() { - return Vector.getMaximum(CornerA.toVector(), CornerB.toVector()).toBlockVector().toLocation(CornerA.getWorld()); + return Vector.getMaximum(CornerBottomLeft.toVector(), CornerTopRight.toVector()).toBlockVector().toLocation(CornerBottomLeft.getWorld()); } public double getMaxHeight() { - return Math.max(CornerA.getY(), CornerB.getY()); + return CornerTopRight.getY(); } /** * Converts all the blocks inside the build to a schematic - * @return + * @return Returns a schematic of the build */ public Schematic convertToSchematic() {