World generation is not working correctly.
This commit is contained in:
parent
99b0e4a692
commit
1a1cbab798
@ -71,7 +71,19 @@ public abstract class Border
|
|||||||
* @param l Location to check if inside the border
|
* @param l Location to check if inside the border
|
||||||
* @return null if l is inside the border otherwise a new Location which is inside
|
* @return null if l is inside the border otherwise a new Location which is inside
|
||||||
*/
|
*/
|
||||||
public abstract Location checkBorder( Location l );
|
public Location checkBorder( Location l )
|
||||||
|
{
|
||||||
|
return checkBorder(l, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given location is inside or outside the border. If it is outside a new location (inside the border)
|
||||||
|
* is returned, otherwise null. Applies padding to the border. (Simulates a larger border using padding.)
|
||||||
|
* @param l Location to check if inside the border
|
||||||
|
* @param padding number of Blocks of padding applied to the border.
|
||||||
|
* @return null if l is inside the border otherwise a new Location which is inside
|
||||||
|
*/
|
||||||
|
public abstract Location checkBorder (Location l, double padding);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of two Location objects defining a rectangle bigger or at size of the border. There are no
|
* Returns an array of two Location objects defining a rectangle bigger or at size of the border. There are no
|
||||||
@ -79,8 +91,6 @@ public abstract class Border
|
|||||||
*/
|
*/
|
||||||
public abstract Location[] getSurroundingRect();
|
public abstract Location[] getSurroundingRect();
|
||||||
|
|
||||||
public abstract Location getCenter();
|
|
||||||
|
|
||||||
public Boolean isActive()
|
public Boolean isActive()
|
||||||
{
|
{
|
||||||
return isActive;
|
return isActive;
|
||||||
@ -105,6 +115,7 @@ public abstract class Border
|
|||||||
isActive = true;
|
isActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static void loadBorders()
|
public static void loadBorders()
|
||||||
{
|
{
|
||||||
bordersFileConf.getList(bordersKey);
|
bordersFileConf.getList(bordersKey);
|
||||||
|
@ -93,13 +93,15 @@ public class CircBorder extends Border implements ConfigurationSerializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location checkBorder( Location l )
|
public Location checkBorder( Location l, double padding )
|
||||||
{
|
{
|
||||||
|
double paddedRadius = radius + padding;
|
||||||
|
|
||||||
double distX = l.getX() - center.getX();
|
double distX = l.getX() - center.getX();
|
||||||
double distZ = l.getZ() - center.getZ();
|
double distZ = l.getZ() - center.getZ();
|
||||||
|
|
||||||
double distanceFromCenterSquared = distX * distX + distZ * distZ;
|
double distanceFromCenterSquared = distX * distX + distZ * distZ;
|
||||||
double radiusSquared = radius * radius;
|
double radiusSquared = paddedRadius * paddedRadius;
|
||||||
|
|
||||||
// inside the border
|
// inside the border
|
||||||
if ( distanceFromCenterSquared <= radiusSquared )
|
if ( distanceFromCenterSquared <= radiusSquared )
|
||||||
@ -108,7 +110,7 @@ public class CircBorder extends Border implements ConfigurationSerializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// outside the border: it's ok to use square-root function here, because this only happens very few times
|
// outside the border: it's ok to use square-root function here, because this only happens very few times
|
||||||
double ratio = radius / Math.sqrt(distanceFromCenterSquared);
|
double ratio = paddedRadius / Math.sqrt(distanceFromCenterSquared);
|
||||||
double newX = center.getX() + ( ratio * distX );
|
double newX = center.getX() + ( ratio * distX );
|
||||||
double newZ = center.getZ() + ( ratio * distZ );
|
double newZ = center.getZ() + ( ratio * distZ );
|
||||||
|
|
||||||
@ -129,10 +131,4 @@ public class CircBorder extends Border implements ConfigurationSerializable
|
|||||||
|
|
||||||
return new Location[]{ l1, l2 };
|
return new Location[]{ l1, l2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getCenter()
|
|
||||||
{
|
|
||||||
return center;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -21,7 +21,6 @@ import de.craftinc.borderprotection.Plugin;
|
|||||||
import de.craftinc.borderprotection.util.PlayerMovementUtil;
|
import de.craftinc.borderprotection.util.PlayerMovementUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -108,22 +107,16 @@ public class RectBorder extends Border implements ConfigurationSerializable
|
|||||||
ChatColor.YELLOW + "Point 2: " + ChatColor.WHITE + rectPoint2.getX() + "," + rectPoint2.getZ();
|
ChatColor.YELLOW + "Point 2: " + ChatColor.WHITE + rectPoint2.getX() + "," + rectPoint2.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given location is inside the rectBorder rectangle. Returns null if yes, otherwise new coordinates.
|
|
||||||
*
|
|
||||||
* @param l location to check
|
|
||||||
* @return null if the player is inside, otherwise a new player location
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Location checkBorder( Location l )
|
public Location checkBorder( Location l, double padding )
|
||||||
{
|
{
|
||||||
// New x and z: null by default
|
// New x and z: null by default
|
||||||
Double[] newXZ = { null, null };
|
Double[] newXZ = { null, null };
|
||||||
|
|
||||||
// check if player is withing the X borders
|
// check if player is withing the X borders
|
||||||
newXZ[0] = _checkBorder(l.getX(), this.rectPoint1.getX(), this.rectPoint2.getX());
|
newXZ[0] = _checkBorder(l.getX(), this.rectPoint1.getX(), this.rectPoint2.getX(), padding);
|
||||||
// check if player is withing the Z borders
|
// check if player is withing the Z borders
|
||||||
newXZ[1] = _checkBorder(l.getZ(), this.rectPoint1.getZ(), this.rectPoint2.getZ());
|
newXZ[1] = _checkBorder(l.getZ(), this.rectPoint1.getZ(), this.rectPoint2.getZ(), padding);
|
||||||
|
|
||||||
// Do nothing, if no new coordinates have been calculated.
|
// Do nothing, if no new coordinates have been calculated.
|
||||||
if ( newXZ[0] == null && newXZ[1] == null )
|
if ( newXZ[0] == null && newXZ[1] == null )
|
||||||
@ -151,12 +144,13 @@ public class RectBorder extends Border implements ConfigurationSerializable
|
|||||||
* @param location part of the location coordinates
|
* @param location part of the location coordinates
|
||||||
* @param border1 one side of the rectangle
|
* @param border1 one side of the rectangle
|
||||||
* @param border2 opposite side of the rectangle
|
* @param border2 opposite side of the rectangle
|
||||||
|
* @param padding a padding (number of block) used to enlarge the border
|
||||||
* @return null if the location is inside, otherwise a new location
|
* @return null if the location is inside, otherwise a new location
|
||||||
*/
|
*/
|
||||||
private static Double _checkBorder( double location, double border1, double border2 )
|
private static Double _checkBorder( double location, double border1, double border2, double padding )
|
||||||
{
|
{
|
||||||
double bigBorder = Math.max(border1, border2);
|
double bigBorder = Math.max(border1, border2) + padding;
|
||||||
double smallBorder = Math.min(border1, border2);
|
double smallBorder = Math.min(border1, border2) - padding;
|
||||||
|
|
||||||
// if location is between borders do nothing
|
// if location is between borders do nothing
|
||||||
if ( location >= smallBorder && location <= bigBorder )
|
if ( location >= smallBorder && location <= bigBorder )
|
||||||
@ -187,15 +181,4 @@ public class RectBorder extends Border implements ConfigurationSerializable
|
|||||||
{
|
{
|
||||||
return new Location[]{ rectPoint1, rectPoint2 };
|
return new Location[]{ rectPoint1, rectPoint2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getCenter()
|
|
||||||
{
|
|
||||||
World w = rectPoint1.getWorld();
|
|
||||||
double x = Math.abs(rectPoint1.getX() - rectPoint2.getX()) / 2.0 + Math.min(rectPoint1.getX(), rectPoint2.getX());
|
|
||||||
double y = rectPoint1.getY();
|
|
||||||
double z = Math.abs(rectPoint1.getZ() - rectPoint2.getZ()) / 2.0 + Math.min(rectPoint1.getZ(), rectPoint2.getZ());
|
|
||||||
|
|
||||||
return new Location(w, x, y, z);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -190,61 +190,14 @@ public class ChunkGenerator
|
|||||||
|
|
||||||
protected static boolean chunkIsInsideBorder(int x, int z, World w, Border b)
|
protected static boolean chunkIsInsideBorder(int x, int z, World w, Border b)
|
||||||
{
|
{
|
||||||
// double xLoc = (double)(x << 4);
|
double xLoc = (double)(x << 4) + 8.0;
|
||||||
// double yLoc = 100.0;
|
double yLoc = 0.0;
|
||||||
// double yLoc = 0.0;
|
double zLoc = (double)(z << 4) + 8.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
|
double padding = (double)(paddingChunksAroundBorder << 4);
|
||||||
Location center = b.getCenter();
|
Location l = new Location(w, xLoc, yLoc, zLoc);
|
||||||
double vecX = center.getX() - (x << 4);
|
|
||||||
double vecZ = center.getZ() - (z << 4);
|
|
||||||
double length = Math.sqrt(vecX*vecX + vecZ*vecZ);
|
|
||||||
|
|
||||||
double padding = paddingChunksAroundBorder << 4;
|
return b.checkBorder(l, padding) == null;
|
||||||
|
|
||||||
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 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)
|
protected static void loadSurroundingChunks(int x, int z, World w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user