mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
fix: even better handling of schematic heights
- Fixes #4083 - Fixes #4050 (with WorldEdit not FAWE) - Pre-requisite of fixing schematic issues in FAWE as well
This commit is contained in:
parent
587a286d05
commit
90f920ba31
@ -34,6 +34,7 @@ import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
|
|||||||
import com.plotsquared.core.util.ChunkManager;
|
import com.plotsquared.core.util.ChunkManager;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.HeightMap;
|
import org.bukkit.HeightMap;
|
||||||
@ -420,7 +421,11 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
if (lastPlotArea != null && name.equals(this.levelName) && chunkX == lastChunkX && chunkZ == lastChunkZ) {
|
if (lastPlotArea != null && name.equals(this.levelName) && chunkX == lastChunkX && chunkZ == lastChunkZ) {
|
||||||
return lastPlotArea;
|
return lastPlotArea;
|
||||||
}
|
}
|
||||||
PlotArea area = UncheckedWorldLocation.at(name, chunkX << 4, 0, chunkZ << 4).getPlotArea();
|
BlockVector3 loc = BlockVector3.at(chunkX << 4, 0, chunkZ << 4);
|
||||||
|
if (lastPlotArea != null && lastPlotArea.getRegion().contains(loc) && lastPlotArea.getRegion().contains(loc)) {
|
||||||
|
return lastPlotArea;
|
||||||
|
}
|
||||||
|
PlotArea area = UncheckedWorldLocation.at(name, loc).getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"Cannot generate chunk that does not belong to a plot area. World: %s",
|
"Cannot generate chunk that does not belong to a plot area. World: %s",
|
||||||
|
@ -69,8 +69,8 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
EnumSet<SchematicFeature> features
|
EnumSet<SchematicFeature> features
|
||||||
) {
|
) {
|
||||||
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
|
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
|
||||||
if ((features.contains(SchematicFeature.ROAD) && Settings.Schematics.PASTE_ROAD_ON_TOP)
|
boolean isRoad = features.contains(SchematicFeature.ROAD);
|
||||||
|| (!features.contains(SchematicFeature.ROAD) && Settings.Schematics.PASTE_ON_TOP)) {
|
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad && Settings.Schematics.PASTE_ON_TOP)) {
|
||||||
minY = world.SCHEM_Y;
|
minY = world.SCHEM_Y;
|
||||||
} else {
|
} else {
|
||||||
minY = world.getMinBuildHeight();
|
minY = world.getMinBuildHeight();
|
||||||
|
@ -162,6 +162,7 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
} else {
|
} else {
|
||||||
minY = hybridPlotWorld.getMinBuildHeight();
|
minY = hybridPlotWorld.getMinBuildHeight();
|
||||||
}
|
}
|
||||||
|
int schemYDiff = (isRoad ? hybridPlotWorld.getRoadYStart() : hybridPlotWorld.getPlotYStart()) - minY;
|
||||||
BaseBlock airBlock = BlockTypes.AIR.getDefaultState().toBaseBlock();
|
BaseBlock airBlock = BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||||
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
||||||
short absX = (short) ((x - hybridPlotWorld.ROAD_OFFSET_X) % size);
|
short absX = (short) ((x - hybridPlotWorld.ROAD_OFFSET_X) % size);
|
||||||
@ -178,10 +179,14 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
for (int y = 0; y < blocks.length; y++) {
|
for (int y = 0; y < blocks.length; y++) {
|
||||||
if (blocks[y] != null) {
|
if (blocks[y] != null) {
|
||||||
queue.setBlock(x, minY + y, z, blocks[y]);
|
queue.setBlock(x, minY + y, z, blocks[y]);
|
||||||
} else if (!isRoad) {
|
} else if (y > schemYDiff) {
|
||||||
// This is necessary, otherwise any blocks not specified in the schematic will remain after a clear
|
// This is necessary, otherwise any blocks not specified in the schematic will remain after a clear.
|
||||||
// Do not set air for road as this may cause cavernous roads when debugroadregen is used
|
// This should only be done where the schematic has actually "started"
|
||||||
queue.setBlock(x, minY + y, z, airBlock);
|
queue.setBlock(x, minY + y, z, airBlock);
|
||||||
|
} else if (isRoad) {
|
||||||
|
queue.setBlock(x, minY + y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
|
||||||
|
} else {
|
||||||
|
queue.setBlock(x, minY + y, z, hybridPlotWorld.MAIN_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
* The Y level at which schematic generation will start, lowest of either road or plot schematic generation.
|
* The Y level at which schematic generation will start, lowest of either road or plot schematic generation.
|
||||||
*/
|
*/
|
||||||
public int SCHEM_Y;
|
public int SCHEM_Y;
|
||||||
|
|
||||||
|
private int plotY;
|
||||||
|
private int roadY;
|
||||||
private Location SIGN_LOCATION;
|
private Location SIGN_LOCATION;
|
||||||
private File root = null;
|
private File root = null;
|
||||||
private int lastOverlayHeightError = Integer.MIN_VALUE;
|
private int lastOverlayHeightError = Integer.MIN_VALUE;
|
||||||
@ -252,13 +255,13 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
|
|
||||||
SCHEM_Y = schematicStartHeight();
|
SCHEM_Y = schematicStartHeight();
|
||||||
|
|
||||||
// plotY and roadY are important to allow plot and/or road schematic "overflow" into each other without causing AIOOB
|
// plotY and roadY are important to allow plot and/or road schematic "overflow" into each other
|
||||||
// exceptions when attempting either to set blocks to, or get block from G_SCH
|
// without causing AIOOB exceptions when attempting either to set blocks to, or get block from G_SCH
|
||||||
// Default plot schematic start height, normalized to the minimum height schematics are pasted from.
|
// Default plot schematic start height, normalized to the minimum height schematics are pasted from.
|
||||||
int plotY = PLOT_HEIGHT - SCHEM_Y;
|
plotY = PLOT_HEIGHT - SCHEM_Y;
|
||||||
int minRoadWall = Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT ? Math.min(ROAD_HEIGHT, WALL_HEIGHT) : ROAD_HEIGHT;
|
int minRoadWall = Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT ? Math.min(ROAD_HEIGHT, WALL_HEIGHT) : ROAD_HEIGHT;
|
||||||
// Default road schematic start height, normalized to the minimum height schematics are pasted from.
|
// Default road schematic start height, normalized to the minimum height schematics are pasted from.
|
||||||
int roadY = minRoadWall - SCHEM_Y;
|
roadY = minRoadWall - SCHEM_Y;
|
||||||
|
|
||||||
int worldGenHeight = getMaxGenHeight() - getMinGenHeight() + 1;
|
int worldGenHeight = getMaxGenHeight() - getMinGenHeight() + 1;
|
||||||
|
|
||||||
@ -267,14 +270,15 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
|
|
||||||
// SCHEM_Y should be normalised to the plot "start" height
|
// SCHEM_Y should be normalised to the plot "start" height
|
||||||
if (schematic3 != null) {
|
if (schematic3 != null) {
|
||||||
plotSchemHeight = maxSchematicHeight = schematic3.getClipboard().getDimensions().getY();
|
plotSchemHeight = schematic3.getClipboard().getDimensions().getY();
|
||||||
if (maxSchematicHeight == worldGenHeight) {
|
if (plotSchemHeight == worldGenHeight) {
|
||||||
SCHEM_Y = getMinGenHeight();
|
SCHEM_Y = getMinGenHeight();
|
||||||
plotY = 0;
|
plotY = 0;
|
||||||
} else if (!Settings.Schematics.PASTE_ON_TOP) {
|
} else if (!Settings.Schematics.PASTE_ON_TOP) {
|
||||||
SCHEM_Y = getMinBuildHeight();
|
SCHEM_Y = getMinBuildHeight();
|
||||||
plotY = 0;
|
plotY = 0;
|
||||||
}
|
}
|
||||||
|
maxSchematicHeight = plotY + plotSchemHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int roadSchemHeight;
|
int roadSchemHeight;
|
||||||
@ -554,4 +558,24 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
return this.root;
|
return this.root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the y value where the plot schematic should be pasted from.
|
||||||
|
*
|
||||||
|
* @return plot schematic y start value
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public int getPlotYStart() {
|
||||||
|
return SCHEM_Y + plotY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the y value where the road schematic should be pasted from.
|
||||||
|
*
|
||||||
|
* @return road schematic y start value
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public int getRoadYStart() {
|
||||||
|
return SCHEM_Y + roadY;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -668,7 +668,7 @@ public class HybridUtils {
|
|||||||
}
|
}
|
||||||
if (condition) {
|
if (condition) {
|
||||||
BaseBlock[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
|
BaseBlock[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
|
||||||
int minY = Settings.Schematics.PASTE_ROAD_ON_TOP ? plotWorld.SCHEM_Y : area.getMinGenHeight() + 1;
|
int minY = plotWorld.getRoadYStart();
|
||||||
int maxDy = Math.max(extend, blocks.length);
|
int maxDy = Math.max(extend, blocks.length);
|
||||||
for (int dy = 0; dy < maxDy; dy++) {
|
for (int dy = 0; dy < maxDy; dy++) {
|
||||||
if (dy > blocks.length - 1) {
|
if (dy > blocks.length - 1) {
|
||||||
|
@ -29,17 +29,17 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DefaultPlotAreaManager implements PlotAreaManager {
|
public class DefaultPlotAreaManager implements PlotAreaManager {
|
||||||
|
|
||||||
final PlotArea[] noPlotAreas = new PlotArea[0];
|
final PlotArea[] noPlotAreas = new PlotArea[0];
|
||||||
private final Map<String, PlotWorld> plotWorlds = new HashMap<>();
|
private final Map<String, PlotWorld> plotWorlds = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull PlotArea[] getAllPlotAreas() {
|
public @NonNull PlotArea[] getAllPlotAreas() {
|
||||||
|
Loading…
Reference in New Issue
Block a user