fix: Adjust schematic height logic when pasting and actually set air as well (#3840)

This commit is contained in:
Jordan 2022-10-13 16:46:29 +01:00 committed by GitHub
parent b740d5854c
commit 11dd013333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 43 deletions

View File

@ -174,8 +174,9 @@ 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 { } else if (!isRoad) {
// 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
queue.setBlock(x, minY + y, z, airBlock); queue.setBlock(x, minY + y, z, airBlock);
} }
} }

View File

@ -21,7 +21,6 @@ package com.plotsquared.core.generator;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.intellectualsites.annotations.DoNotUse; import com.intellectualsites.annotations.DoNotUse;
import com.intellectualsites.annotations.NotPublic;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
@ -75,6 +74,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public short PATH_WIDTH_UPPER; public short PATH_WIDTH_UPPER;
public HashMap<Integer, BaseBlock[]> G_SCH; public HashMap<Integer, BaseBlock[]> G_SCH;
public HashMap<Integer, BiomeType> G_SCH_B; public HashMap<Integer, BiomeType> G_SCH_B;
/**
* 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 Location SIGN_LOCATION; private Location SIGN_LOCATION;
private File root = null; private File root = null;
@ -267,34 +269,64 @@ public class HybridPlotWorld extends ClassicPlotWorld {
int oddshift = (this.ROAD_WIDTH & 1); int oddshift = (this.ROAD_WIDTH & 1);
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
// 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.
int plotY = PLOT_HEIGHT - SCHEM_Y; int 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.
int roadY = minRoadWall - SCHEM_Y; int roadY = minRoadWall - SCHEM_Y;
int worldHeight = getMaxGenHeight() - getMinGenHeight() + 1; int worldGenHeight = getMaxGenHeight() - getMinGenHeight() + 1;
int maxSchematicHeight = 0;
int plotSchemHeight = 0;
// 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) {
if (schematic3.getClipboard().getDimensions().getY() == worldHeight) { plotSchemHeight = maxSchematicHeight = schematic3.getClipboard().getDimensions().getY();
SCHEM_Y = plotY = 0; if (maxSchematicHeight == worldGenHeight) {
SCHEM_Y = getMinGenHeight();
plotY = 0;
} else if (!Settings.Schematics.PASTE_ON_TOP) { } else if (!Settings.Schematics.PASTE_ON_TOP) {
SCHEM_Y = plotY = getMinBuildHeight() - getMinGenHeight(); SCHEM_Y = getMinBuildHeight();
plotY = 0;
} }
} }
int roadSchemHeight;
if (schematic1 != null) { if (schematic1 != null) {
if (schematic1.getClipboard().getDimensions().getY() == worldHeight) { roadSchemHeight = schematic1.getClipboard().getDimensions().getY();
SCHEM_Y = roadY = getMinGenHeight(); maxSchematicHeight = Math.max(roadSchemHeight, maxSchematicHeight);
if (schematic3 != null && schematic3.getClipboard().getDimensions().getY() != worldHeight if (maxSchematicHeight == worldGenHeight) {
&& !Settings.Schematics.PASTE_ON_TOP) { SCHEM_Y = getMinGenHeight();
plotY = PLOT_HEIGHT; roadY = 0; // Road is the lowest schematic
if (schematic3 != null && schematic3.getClipboard().getDimensions().getY() != worldGenHeight) {
// Road is the lowest schematic. Normalize plotY to it.
if (Settings.Schematics.PASTE_ON_TOP) {
plotY = PLOT_HEIGHT - getMinGenHeight();
} else {
plotY = getMinBuildHeight() - getMinGenHeight();
}
} }
} else if (!Settings.Schematics.PASTE_ROAD_ON_TOP) { } else if (!Settings.Schematics.PASTE_ROAD_ON_TOP) {
SCHEM_Y = roadY = getMinBuildHeight(); if (SCHEM_Y == getMinGenHeight()) { // Only possible if plot schematic is enabled
if (schematic3 != null && schematic3.getClipboard().getDimensions().getY() != worldHeight // Plot is still the lowest schematic, normalize roadY to it
&& !Settings.Schematics.PASTE_ON_TOP) { roadY = getMinBuildHeight() - getMinGenHeight();
plotY = PLOT_HEIGHT; } else if (schematic3 != null) {
SCHEM_Y = getMinBuildHeight();
roadY = 0;// Road is the lowest schematic
if (Settings.Schematics.PASTE_ON_TOP) {
// Road is the lowest schematic. Normalize plotY to it.
plotY = PLOT_HEIGHT - getMinBuildHeight();
} }
maxSchematicHeight = Math.max(maxSchematicHeight, plotY + plotSchemHeight);
}
} else {
roadY = minRoadWall - SCHEM_Y;
maxSchematicHeight = Math.max(maxSchematicHeight, roadY + roadSchemHeight);
} }
} }
@ -331,7 +363,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
y + min.getBlockY(), y + min.getBlockY(),
z + min.getBlockZ() z + min.getBlockZ()
)); ));
if (!id.getBlockType().getMaterial().isAir()) {
schem3PopulationNeeded |= id.hasNbtData(); schem3PopulationNeeded |= id.hasNbtData();
addOverlayBlock( addOverlayBlock(
(short) (x + shift + oddshift + centerShiftX), (short) (x + shift + oddshift + centerShiftX),
@ -339,10 +370,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
(short) (z + shift + oddshift + centerShiftZ), (short) (z + shift + oddshift + centerShiftZ),
id, id,
false, false,
h3 maxSchematicHeight
); );
} }
}
if (blockArrayClipboard3.hasBiomes()) { if (blockArrayClipboard3.hasBiomes()) {
BiomeType biome = blockArrayClipboard3.getBiome(BlockVector2.at( BiomeType biome = blockArrayClipboard3.getBiome(BlockVector2.at(
x + min.getBlockX(), x + min.getBlockX(),
@ -391,19 +421,24 @@ public class HybridPlotWorld extends ClassicPlotWorld {
y + min.getBlockY(), y + min.getBlockY(),
z + min.getBlockZ() z + min.getBlockZ()
)); ));
if (!id.getBlockType().getMaterial().isAir()) {
schem1PopulationNeeded |= id.hasNbtData(); schem1PopulationNeeded |= id.hasNbtData();
addOverlayBlock((short) (x - shift), (short) (y + roadY), (short) (z + shift + oddshift), id, false, h1); addOverlayBlock(
(short) (x - shift),
(short) (y + roadY),
(short) (z + shift + oddshift),
id,
false,
maxSchematicHeight
);
addOverlayBlock( addOverlayBlock(
(short) (z + shift + oddshift), (short) (z + shift + oddshift),
(short) (y + roadY), (short) (y + roadY),
(short) (shift - x + (oddshift - 1)), (short) (shift - x + (oddshift - 1)),
id, id,
true, true,
h1 maxSchematicHeight
); );
} }
}
if (blockArrayClipboard1.hasBiomes()) { if (blockArrayClipboard1.hasBiomes()) {
BiomeType biome = blockArrayClipboard1.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ())); BiomeType biome = blockArrayClipboard1.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
addOverlayBiome((short) (x - shift), (short) (z + shift + oddshift), biome); addOverlayBiome((short) (x - shift), (short) (z + shift + oddshift), biome);
@ -430,10 +465,15 @@ public class HybridPlotWorld extends ClassicPlotWorld {
y + min.getBlockY(), y + min.getBlockY(),
z + min.getBlockZ() z + min.getBlockZ()
)); ));
if (!id.getBlockType().getMaterial().isAir()) {
schem2PopulationNeeded |= id.hasNbtData(); schem2PopulationNeeded |= id.hasNbtData();
addOverlayBlock((short) (x - shift), (short) (y + roadY), (short) (z - shift), id, false, h2); addOverlayBlock(
} (short) (x - shift),
(short) (y + roadY),
(short) (z - shift),
id,
false,
maxSchematicHeight
);
} }
if (blockArrayClipboard2.hasBiomes()) { if (blockArrayClipboard2.hasBiomes()) {
BiomeType biome = blockArrayClipboard2.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ())); BiomeType biome = blockArrayClipboard2.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
@ -443,6 +483,10 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
} }
/**
* @deprecated This method should not be available for public API usage and will be made private.
*/
@Deprecated(forRemoval = true, since = "TODO")
public void addOverlayBlock(short x, short y, short z, BaseBlock id, boolean rotate, int height) { public void addOverlayBlock(short x, short y, short z, BaseBlock id, boolean rotate, int height) {
if (z < 0) { if (z < 0) {
z += this.SIZE; z += this.SIZE;
@ -462,13 +506,22 @@ public class HybridPlotWorld extends ClassicPlotWorld {
if (y >= height) { if (y >= height) {
if (y > lastOverlayHeightError) { if (y > lastOverlayHeightError) {
lastOverlayHeightError = y; lastOverlayHeightError = y;
LOGGER.error(String.format("Error adding overlay block. `y > height`. y=%s, height=%s", y, height)); LOGGER.error(
"Error adding overlay block in world {}. `y > height`. y={}, height={}",
getWorldName(),
y,
height
);
} }
return; return;
} }
existing[y] = id; existing[y] = id;
} }
/**
* @deprecated This method should not be available for public API usage and will be made private.
*/
@Deprecated(forRemoval = true, since = "TODO")
public void addOverlayBiome(short x, short z, BiomeType id) { public void addOverlayBiome(short x, short z, BiomeType id) {
if (z < 0) { if (z < 0) {
z += this.SIZE; z += this.SIZE;