PlotSquared/Core/src/main/java/com/plotsquared/core/util/RegionUtil.java
Jordan 9f632af0ae
Implement extended world heights from Y-64 to Y319 #3473 (#3473)
* Begin to implement extended world heights:
 - Implemented in Bukkit module (and where required in Core module)

* Implement extended world heights into core module

* Add min gen height to setup,

* Default gen/build heights based on minecraft version

* Few fixes

* Fix up queues

* Address comments

* Make road schematic stuff slightly more efficient by sharing queues

* Minor fixes, don't overlay error many times for the same y

* Fix incorrect schematic paste height, undo changes to HybridUtils

* Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish

* Process chunks in order when regenerating all roads

* Address comments

* Address comments

* Ground level//bedrock is at min gen height
 - Add comment on == rather than <= being used
 - It's because it's only checking for the bedrock layer being broken if that's disabled

* Fix offset for min build height in SchematicHandler

* Better javadoc

Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>

* Address inclusivity issues for max world height

* Javadocs/comments/deprecation

* Use world min/max heights if present in QueueCoordinator

* Address some deprecations for regions and biome setting

* Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit

* Use minGenHeight + 1 rather than build height in AugmentedUtils

* Create utility method for layer index in GenChunk

* Correct height in HybridUtils, also use minGenHeight + 1

* Don't magically split to 128 height in regeneration

* Add utility methods for world height in QueueCoordinator

* Clean up ClassicPlotManager road creation/removal

* Start generation at min gen height if bedrock is disabled

* min gen height is set in PlotArea

* Add note on schem y normalisation

* Improve plot getVolume method readability

* Don't overly extend height when regenerating road region

* y index utility method in ChunknQueueCoordinator

* Layer index utility method in LocalChunk

* Use version min/max heights if world not present in QueueCoordinator

* Fix min -> max

* Don't allow players to modify outside build height when using plot set  / schematics.
 - Also fixes schematic height issues

* Remove debug

* Address comments

* Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded)

* Fix "security" issue that was already present

* Ensure sign isn't physicsed

Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00

125 lines
5.2 KiB
Java

/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.Iterator;
public class RegionUtil {
public static @NonNull Location[] getCorners(
final @NonNull String world,
final @NonNull CuboidRegion region
) {
final BlockVector3 min = region.getMinimumPoint();
final BlockVector3 max = region.getMaximumPoint();
return new Location[]{Location.at(world, min), Location.at(world, max)};
}
public static @NonNull Location[] getCorners(String world, Collection<CuboidRegion> regions) {
CuboidRegion aabb = getAxisAlignedBoundingBox(regions);
return getCorners(world, aabb);
}
/**
* Create a minimum {@link CuboidRegion} containing all given regions.
*
* @param regions The regions the bounding box should contain.
* @return a CuboidRegion that contains all given regions.
*/
public static @NonNull CuboidRegion getAxisAlignedBoundingBox(Iterable<CuboidRegion> regions) {
Iterator<CuboidRegion> iterator = regions.iterator();
if (!iterator.hasNext()) {
throw new IllegalArgumentException("No regions given");
}
CuboidRegion next = iterator.next();
BlockVector3 min = next.getMinimumPoint();
BlockVector3 max = next.getMaximumPoint();
while (iterator.hasNext()) {
next = iterator.next();
// as max >= min, this is enough to check
min = min.getMinimum(next.getMinimumPoint());
max = max.getMaximum(next.getMaximumPoint());
}
return new CuboidRegion(min, max);
}
@Deprecated(forRemoval = true, since = "TODO")
public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) {
return createRegion(pos1x, pos2x, 0, 255, pos1z, pos2z);
}
public static CuboidRegion createRegion(
int pos1x, int pos2x, int pos1y, int pos2y, int pos1z,
int pos2z
) {
BlockVector3 pos1 = BlockVector3.at(pos1x, pos1y, pos1z);
BlockVector3 pos2 = BlockVector3.at(pos2x, pos2y, pos2z);
return new CuboidRegion(pos1, pos2);
}
public static boolean contains(CuboidRegion region, int x, int z) {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ();
}
public static boolean contains(CuboidRegion region, int x, int y, int z) {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ() && y >= min
.getY() && y <= max.getY();
}
public static @NonNull Rectangle2D toRectangle(final @NonNull CuboidRegion region) {
final BlockVector2 min = region.getMinimumPoint().toBlockVector2();
final BlockVector2 max = region.getMaximumPoint().toBlockVector2();
return new Rectangle2D.Double(min.getX(), min.getZ(), max.getX(), max.getZ());
}
// Because WE (not fawe) lack this for CuboidRegion
public static boolean intersects(CuboidRegion region, CuboidRegion other) {
BlockVector3 regionMin = region.getMinimumPoint();
BlockVector3 regionMax = region.getMaximumPoint();
BlockVector3 otherMin = other.getMinimumPoint();
BlockVector3 otherMax = other.getMaximumPoint();
return otherMin.getX() <= regionMax.getX() && otherMax.getX() >= regionMin.getX()
&& otherMin.getZ() <= regionMax.getZ() && otherMax.getZ() >= regionMin.getZ();
}
}