From 9a85080bf62777172a51ca39d3847ebf3d163feb Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 14 Jan 2022 10:46:04 +0100 Subject: [PATCH] Allow restoration of road schematic height calculation behaviour from pre 6.1.4 (#3444) --- .../core/configuration/Settings.java | 6 +++++ .../core/generator/ClassicPlotManager.java | 25 ++++--------------- .../core/generator/ClassicPlotWorld.java | 9 +++++++ .../core/generator/HybridPlotWorld.java | 13 ++++++++-- .../core/generator/HybridUtils.java | 5 +++- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index e8a52634a..70be6ece6 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -417,6 +417,12 @@ public class Settings extends Config { " - This will still only paste a schematic with a plot's bounds.", " - If a schematic is too big, it will cut off, and if too small, will not full the plot."}) public static boolean PASTE_MISMATCHES = true; + @Comment({"If the wall height should be taken into account when calculating the road schematic paste height", + " - If true, will use the lower of wall and road height.", + " - If true, will ensure correct schematic behaviour (no parts are cut off).", + " - Set to false if you experience the road being set one block too low", + " (only for road schematics created pre 6.1.4)."}) + public static boolean USE_WALL_IN_ROAD_SCHEM_HEIGHT = true; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index 3b12871f4..e1e2ebfc8 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -506,10 +506,7 @@ public class ClassicPlotManager extends SquarePlotManager { Location.at( classicPlotWorld.getWorldName(), sx, - Math.min( - classicPlotWorld.PLOT_HEIGHT, - Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) - ) + 1, + classicPlotWorld.schematicStartHeight() + 1, sz + 1 ), Location.at(classicPlotWorld.getWorldName(), ex, maxY, ez - 1), BlockTypes.AIR.getDefaultState() @@ -584,10 +581,7 @@ public class ClassicPlotManager extends SquarePlotManager { Location.at( classicPlotWorld.getWorldName(), sx + 1, - Math.min( - classicPlotWorld.PLOT_HEIGHT, - Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) - ) + 1, + classicPlotWorld.schematicStartHeight() + 1, sz ), Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez), @@ -682,10 +676,7 @@ public class ClassicPlotManager extends SquarePlotManager { Location.at( classicPlotWorld.getWorldName(), sx, - Math.min( - classicPlotWorld.PLOT_HEIGHT, - Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) - ) + 1, + classicPlotWorld.schematicStartHeight() + 1, sz ), Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), @@ -725,10 +716,7 @@ public class ClassicPlotManager extends SquarePlotManager { Location.at( classicPlotWorld.getWorldName(), sx, - Math.min( - classicPlotWorld.PLOT_HEIGHT, - Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) - ) + 1, + classicPlotWorld.schematicStartHeight() + 1, sz ), Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), @@ -767,10 +755,7 @@ public class ClassicPlotManager extends SquarePlotManager { Location.at( classicPlotWorld.getWorldName(), sx, - Math.min( - classicPlotWorld.PLOT_HEIGHT, - Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) - ) + 1, + classicPlotWorld.schematicStartHeight() + 1, sz ), Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java index d8408ccf5..17db4a452 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java @@ -28,6 +28,7 @@ package com.plotsquared.core.generator; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.inject.annotations.WorldConfig; @@ -138,4 +139,12 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block"); } + int schematicStartHeight() { + int plotRoadMin = Math.min(PLOT_HEIGHT, ROAD_HEIGHT); + if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) { + return plotRoadMin; + } + return Math.min(WALL_HEIGHT, plotRoadMin); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index 813942384..2b6945c61 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -253,9 +253,10 @@ public class HybridPlotWorld extends ClassicPlotWorld { int shift = this.ROAD_WIDTH / 2; int oddshift = (this.ROAD_WIDTH & 1) == 0 ? 0 : 1; - SCHEM_Y = Math.min(PLOT_HEIGHT, Math.min(WALL_HEIGHT, ROAD_HEIGHT)); + SCHEM_Y = schematicStartHeight(); int plotY = PLOT_HEIGHT - SCHEM_Y; - int roadY = Math.min(ROAD_HEIGHT, WALL_HEIGHT) - SCHEM_Y; + int minRoadWall = Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT ? Math.min(ROAD_HEIGHT, WALL_HEIGHT) : ROAD_HEIGHT; + int roadY = minRoadWall - SCHEM_Y; if (schematic3 != null) { if (schematic3.getClipboard().getDimensions().getY() == 256) { @@ -350,6 +351,10 @@ public class HybridPlotWorld extends ClassicPlotWorld { short w1 = (short) d1.getX(); short l1 = (short) d1.getZ(); short h1 = (short) d1.getY(); + // Workaround for schematic height issue if proper calculation of road schematic height is disabled + if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) { + h1 += Math.max(ROAD_HEIGHT - WALL_HEIGHT, 0); + } BlockVector3 min = blockArrayClipboard1.getMinimumPoint(); for (short x = 0; x < w1; x++) { @@ -383,6 +388,10 @@ public class HybridPlotWorld extends ClassicPlotWorld { short w2 = (short) d2.getX(); short l2 = (short) d2.getZ(); short h2 = (short) d2.getY(); + // Workaround for schematic height issue if proper calculation of road schematic height is disabled + if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) { + h2 += Math.max(ROAD_HEIGHT - WALL_HEIGHT, 0); + } min = blockArrayClipboard2.getMinimumPoint(); for (short x = 0; x < w2; x++) { for (short z = 0; z < l2; z++) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 625adb2bb..686e4f97f 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -504,7 +504,10 @@ public class HybridUtils { Location top = plot.getTopAbs(); final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea(); PlotManager plotManager = plotworld.getPlotManager(); - int schemY = Math.min(plotworld.PLOT_HEIGHT, Math.min(plotworld.WALL_HEIGHT, plotworld.ROAD_HEIGHT)); + // Do not use plotworld#schematicStartHeight() here as we want to restore the pre 6.1.4 way of doing it if + // USE_WALL_IN_ROAD_SCHEM_HEIGHT is false + int schemY = Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT ? + Math.min(plotworld.PLOT_HEIGHT, Math.min(plotworld.WALL_HEIGHT, plotworld.ROAD_HEIGHT)) : plotworld.ROAD_HEIGHT; int sx = bot.getX() - plotworld.ROAD_WIDTH + 1; int sz = bot.getZ() + 1; int sy = Settings.Schematics.PASTE_ROAD_ON_TOP ? schemY : plot.getArea().getMinBuildHeight();