Skip to content

Commit

Permalink
feat: new plot height calculation
Browse files Browse the repository at this point in the history
* issue: Plot-System throw an exception when a plot height is out of its MIN_WORLD_HEIGHT and MAX_WORLD_HEIGHT value.

* fix: I created a set threshold whether the plot is in bound of vanilla y-level or not, all plot out of bounds is then get catches and paste on MIN_WORLD_HEIGHT
  • Loading branch information
tintinkung committed Apr 25, 2024
1 parent 31327fc commit 98c8841
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<build.number>SNAPSHOT</build.number>
<build.number>build.1</build.number>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ public String getRegionName() {
@Beta
@Override
public int getPlotHeight() throws IOException {
return getPlot().getVersion() >= 3 ? MIN_WORLD_HEIGHT + getWorldHeight() : getPlotHeightCentered();
int worldHeight;
try { worldHeight = getWorldHeight(); }
catch (IOException ex) { worldHeight = MIN_WORLD_HEIGHT; }
return getPlot().getVersion() >= 3 ? MIN_WORLD_HEIGHT + worldHeight : getPlotHeightCentered();
}

@Beta
@Override
public int getPlotHeightCentered() throws IOException {
return Math.min(MIN_WORLD_HEIGHT + getWorldHeight() + super.getPlotHeightCentered(), PlotWorld.MAX_WORLD_HEIGHT);
int worldHeight;
try { worldHeight = getWorldHeight(); }
catch (IOException ex) { worldHeight = 0; }
return Math.min(MIN_WORLD_HEIGHT + worldHeight + super.getPlotHeightCentered(), PlotWorld.MAX_WORLD_HEIGHT);
}

/**
Expand All @@ -101,14 +107,13 @@ public int getPlotHeightCentered() throws IOException {
public int getWorldHeight() throws IOException {
Clipboard clipboard = FaweAPI.load(getPlot().getOutlinesSchematic());
int plotHeight = clipboard != null ? clipboard.getMinimumPoint().getBlockY() : MIN_WORLD_HEIGHT;
int maxBuildingHeight = 128; // Highest building height a plot can be
int groundLayer = 16; // Additional ground layer the plot use to save as schematic need to be included for plot's y-level

// Plots created below min world height are not supported
if (plotHeight < MIN_WORLD_HEIGHT) throw new IOException("Plot height is not supported");

// Move Y height to a usable value below 256 blocks
while (plotHeight >= 150) {
plotHeight -= 150;
}
// Plots created outside of vanilla build limit is thrown to be handled by case
if (plotHeight + groundLayer < MIN_WORLD_HEIGHT
| plotHeight + maxBuildingHeight > MAX_WORLD_HEIGHT)
throw new IOException("Plot height is out of range");
return plotHeight;
}

Expand Down

0 comments on commit 98c8841

Please sign in to comment.