Remove hardcoding of world limits (#1199)

* Remove hardcoding of world limits
 - seems to be working fine without the datapack for world height changing
 - particular attention should be given to LocalBlockVectorSet and MathMan changes

* update adapters

* Override getMinY in various classes and ensure selections have a world attached to them

* no message

* Address comments
 - Fix for lighting mode 1

* A few more changes

* Fix LocalBlockVectorSet

* Fix range statement

* Various fixes/comment-addressing
- There's not much point in having a different file name now for history. We've broken it before...
- Fix history read/write
- Fix range on for loops in CharBlocks

* undo bad CharBlocks change

* Fix history y level

* Fix biome history

* Fix lighting

* Fix /up

* Make regen fail not because of these changes

* Fixes for y < 0

* Fix isEmpty where only the uppermost chunksection is edited

* Fix javadocs/FAWE annotations

* Better explain why BiomeMath is removed

* If history task throws an error, it should only be caught and printed if not completing now.

* Min|max world heights for new patterns

* Load biomes from NMS instead of bukkit (#1200)

* Update adapters

* Update adapters

* Don't initialise BlockTypes when biomes aren't set up yet so all BiomeTypes.BIOME are no longer null thanks.

* Address some comments.

* rename layer -> sectionIndex to imply inclusivity

* Javadoctored.

Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
dordsor21
2021-08-17 22:13:51 +01:00
committed by GitHub
parent 5b2bd45d86
commit 1d9b1a3d5e
110 changed files with 1489 additions and 677 deletions

View File

@ -202,6 +202,11 @@ public class AbstractDelegateExtent implements Extent {
return extent.getMaxY();
}
@Override
public int getMinY() {
return extent.getMinY();
}
@Override
public boolean relight(int x, int y, int z) {
return extent.relight(x, y, z);
@ -317,7 +322,7 @@ public class AbstractDelegateExtent implements Extent {
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(
int x, @Range(from = 0, to = 255) int y,
int x, int y,
int z, T block
) throws WorldEditException {
return extent.setBlock(x, y, z, block);

View File

@ -200,9 +200,16 @@ public interface Extent extends InputExtent, OutputExtent {
- TODO: actually optimize these
*/
/**
* Returns the highest solid 'terrain' block.
*
* @param x the X coordinate
* @param z the Z coordinate
* @param minY minimal height
* @param maxY maximal height
* @return height of highest block found or 'minY'
*/
default int getHighestTerrainBlock(final int x, final int z, int minY, int maxY) {
maxY = Math.min(maxY, Math.max(0, maxY));
minY = Math.max(0, minY);
for (int y = maxY; y >= minY; --y) {
BlockState block = getBlock(x, y, z);
if (block.getBlockType().getMaterial().isMovementBlocker()) {
@ -212,9 +219,19 @@ public interface Extent extends InputExtent, OutputExtent {
return minY;
}
/**
* Returns the highest solid 'terrain' block.
*
* @param x the X coordinate
* @param z the Z coordinate
* @param minY minimal height
* @param maxY maximal height
* @param filter a mask of blocks to consider, or null to consider any solid (movement-blocking) block
* @return height of highest block found or 'minY'
*/
default int getHighestTerrainBlock(final int x, final int z, int minY, int maxY, Mask filter) {
maxY = Math.min(maxY, Math.max(0, maxY));
minY = Math.max(0, minY);
maxY = Math.min(maxY, getMaxY());
minY = Math.max(getMinY(), minY);
MutableBlockVector3 mutable = new MutableBlockVector3();
@ -226,6 +243,18 @@ public interface Extent extends InputExtent, OutputExtent {
return minY;
}
/**
* Returns the nearest surface layer (up/down from start)
* <p>
* TODO: Someone understand this..?
*
* @param x x to search from
* @param z y to search from
* @param y z to search from
* @param minY min y to search (inclusive)
* @param maxY max y to search (inclusive)
* @return nearest surface layer
*/
default int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) {
int clearanceAbove = maxY - y;
int clearanceBelow = y - minY;
@ -255,7 +284,7 @@ public interface Extent extends InputExtent, OutputExtent {
for (int layer = y - clearance - 1; layer >= minY; layer--) {
block = getBlock(x, layer, z);
if (block.getBlockType().getMaterial().isMovementBlocker() == state) {
return ((layer + offset) << 4) + 0;
return (layer + offset) << 4;
}
data1 = PropertyGroup.LEVEL.get(block);
}
@ -272,18 +301,20 @@ public interface Extent extends InputExtent, OutputExtent {
return (state ? minY : maxY) << 4;
}
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, minY, maxY, ignoreAir);
}
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, minY, maxY);
}
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, true);
}
/**
* Gets y value for the nearest block that is considered the surface of the terrain (cave roof/floor, mountain surface,
* etc) where the block conforms to a given mask. Searches in the x,z column given.
*
* @param x column x
* @param z column z
* @param y start y
* @param minY minimum y height to consider. Inclusive.
* @param maxY maximum y height to consider. Inclusive.
* @param failedMin if nothing found, the minimum y value to return if returning min
* @param failedMax if nothing found, the maximum y value to return if returning max
* @param mask mask to test blocks against
* @return The y value of the nearest terrain block
*/
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
y = Math.max(minY, Math.min(maxY, y));
int clearanceAbove = maxY - y;
@ -320,6 +351,68 @@ public interface Extent extends InputExtent, OutputExtent {
return state ? failedMin : failedMax;
}
/**
* Gets y value for the nearest block that is considered the surface of the terrain (cave roof/floor, mountain surface,
* etc). Searches in the x,z column given.
*
* @param x column x
* @param z column z
* @param y start y
* @param minY minimum y height to consider. Inclusive.
* @param maxY maximum y height to consider. Inclusive.
* @param ignoreAir if air at the final value if no block found should be considered for return, else return -1
* @return The y value of the nearest terrain block
*/
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, minY, maxY, ignoreAir);
}
/**
* Gets y value for the nearest block that is considered the surface of the terrain (cave roof/floor, mountain surface,
* etc). Searches in the x,z column given.
*
* @param x column x
* @param z column z
* @param y start y
* @param minY minimum y height to consider. Inclusive.
* @param maxY maximum y height to consider. Inclusive.
* @return The y value of the nearest terrain block
*/
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, minY, maxY);
}
/**
* Gets y value for the nearest block that is considered the surface of the terrain (cave roof/floor, mountain surface,
* etc). Searches in the x,z column given.
*
* @param x column x
* @param z column z
* @param y start y
* @param minY minimum y height to consider. Inclusive.
* @param maxY maximum y height to consider. Inclusive.
* @param failedMin if nothing found, the minimum y value to return if returning min
* @param failedMax if nothing found, the maximum y value to return if returning max
* @return The y value of the nearest terrain block
*/
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, true);
}
/**
* Gets y value for the nearest block that is considered the surface of the terrain (cave roof/floor, mountain surface,
* etc). Searches in the x,z column given.
*
* @param x column x
* @param z column z
* @param y start y
* @param minY minimum y height to consider. Inclusive.
* @param maxY maximum y height to consider. Inclusive.
* @param failedMin if nothing found, the minimum y value to return if returning min
* @param failedMax if nothing found, the maximum y value to return if returning max
* @param ignoreAir if air at the final value if no block found should be considered for return, else return -1
* @return The y value of the nearest terrain block
*/
default int getNearestSurfaceTerrainBlock(
int x,
int z,
@ -367,7 +460,7 @@ public interface Extent extends InputExtent, OutputExtent {
}
}
int result = state ? failedMin : failedMax;
if (result > 0 && !ignoreAir) {
if (result > minY && !ignoreAir) {
block = getBlock(x, result, z);
return block.getBlockType().getMaterial().isAir() ? -1 : result;
}
@ -444,12 +537,13 @@ public interface Extent extends InputExtent, OutputExtent {
spawnResource(region, new OreGen(this, mask, material, size, minY, maxY), rarity, frequency);
}
//TODO: probably update these for 1.18 etc.
default void addOres(Region region, Mask mask) throws WorldEditException {
addOre(region, mask, BlockTypes.DIRT.getDefaultState(), 33, 10, 100, 0, 255);
addOre(region, mask, BlockTypes.GRAVEL.getDefaultState(), 33, 8, 100, 0, 255);
addOre(region, mask, BlockTypes.ANDESITE.getDefaultState(), 33, 10, 100, 0, 79);
addOre(region, mask, BlockTypes.DIORITE.getDefaultState(), 33, 10, 100, 0, 79);
addOre(region, mask, BlockTypes.GRANITE.getDefaultState(), 33, 10, 100, 0, 79);
addOre(region, mask, BlockTypes.DIRT.getDefaultState(), 33, 10, 100, getMinY(), getMaxY());
addOre(region, mask, BlockTypes.GRAVEL.getDefaultState(), 33, 8, 100, getMinY(), getMaxY());
addOre(region, mask, BlockTypes.ANDESITE.getDefaultState(), 33, 10, 100, getMinY(), 79);
addOre(region, mask, BlockTypes.DIORITE.getDefaultState(), 33, 10, 100, getMinY(), 79);
addOre(region, mask, BlockTypes.GRANITE.getDefaultState(), 33, 10, 100, getMinY(), 79);
addOre(region, mask, BlockTypes.COAL_ORE.getDefaultState(), 17, 20, 100, 0, 127);
addOre(region, mask, BlockTypes.IRON_ORE.getDefaultState(), 9, 20, 100, 0, 63);
addOre(region, mask, BlockTypes.GOLD_ORE.getDefaultState(), 9, 2, 100, 0, 31);
@ -556,11 +650,11 @@ public interface Extent extends InputExtent, OutputExtent {
}
default int getMinY() {
return 0;
return getMinimumPoint().getY();
}
default int getMaxY() {
return 255;
return getMaximumPoint().getY();
}
/**

View File

@ -347,7 +347,7 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
if (!pasteAir && block.getBlockType().getMaterial().isAir()) {
continue;
}
if (pos.getY() < 0) {
if (pos.getY() < extent.getMinY()) {
throw new RuntimeException("Y-Position cannot be less than 0!");
}
extent.setBlock(xx, yy, zz, block);