From 99b0e4a69245de9e65225e79cc05ffb7f11878f6 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sun, 9 Jun 2013 19:14:49 +0200 Subject: [PATCH] Second approach for generating padding around border. Still a not so great solution. --- .../borderprotection/util/ChunkGenerator.java | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java b/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java index ca83c19..59ce0f4 100644 --- a/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java +++ b/src/main/java/de/craftinc/borderprotection/util/ChunkGenerator.java @@ -190,23 +190,61 @@ public class ChunkGenerator protected static boolean chunkIsInsideBorder(int x, int z, World w, Border b) { - // FIXME: the following code makes round border not so round! - - double xLoc = (double)(x << 4); - double yLoc = 100.0; - double zLoc = (double)(z << 4); +// double xLoc = (double)(x << 4); +// double yLoc = 100.0; +// double yLoc = 0.0; +// double zLoc = (double)(z << 4); +// +// Location center = b.getCenter(); +// double centerX = center.getX(); +// double centerZ = center.getZ(); +// +// double padding = paddingChunksAroundBorder << 4; +// +// if (Math.abs(xLoc) < padding) +// { +// xLoc = centerX; +// } +// else +// { +// xLoc = centerX < xLoc ? xLoc-padding : xLoc+padding; +// xLoc = centerX < xLoc ? xLoc-padding : xLoc+padding; +// } +// +// if (Math.abs(zLoc) < padding) +// { +// zLoc = centerZ; +// } +// else +// { +// zLoc = centerZ < zLoc ? zLoc-padding : zLoc+padding; +// zLoc = centerZ < zLoc ? zLoc-padding : zLoc+padding; +// } +// +// Location chunkLocation = new Location(w, xLoc, yLoc, zLoc); +// return b.checkBorder(chunkLocation) == null; +// + // make the location to check the length of 'paddingChunksAroundBorder' closer to center of the border Location center = b.getCenter(); - double centerX = center.getX(); - double centerZ = center.getZ(); + double vecX = center.getX() - (x << 4); + double vecZ = center.getZ() - (z << 4); + double length = Math.sqrt(vecX*vecX + vecZ*vecZ); double padding = paddingChunksAroundBorder << 4; - xLoc = centerX < xLoc ? xLoc-padding : xLoc+padding; - zLoc = centerZ < zLoc ? zLoc-padding : zLoc+padding; + if (Math.abs(length) < padding) + { + vecX = vecZ = 0.0; // avoid 'crossing' the center of the border + } + else + { + vecX -= vecX / length * padding; + vecZ -= vecZ / length * padding; + } - Location chunkLocation = new Location(w, xLoc, yLoc, zLoc); - return b.checkBorder(chunkLocation) == null; + Location locationMinusPadding = new Location(w, center.getX()+vecX, 0.0, center.getZ()+vecZ); + return b.checkBorder(locationMinusPadding) == null; } protected static void loadSurroundingChunks(int x, int z, World w) @@ -217,7 +255,7 @@ public class ChunkGenerator { for (int j=-radius; j