Grav brush: move to bottom, not down one

Dieser Commit ist enthalten in:
Kenzie Togami 2019-07-06 15:41:11 -07:00
Ursprung 3ad80665d8
Commit 2ee71cc72f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81

Datei anzeigen

@ -46,25 +46,40 @@ public class GravityBrush implements Brush {
Set<BlockVector3> removedBlocks = new LinkedHashSet<>(); Set<BlockVector3> removedBlocks = new LinkedHashSet<>();
for (double x = position.getX() - size; x <= position.getX() + size; x++) { for (double x = position.getX() - size; x <= position.getX() + size; x++) {
for (double z = position.getZ() - size; z <= position.getZ() + size; z++) { for (double z = position.getZ() - size; z <= position.getZ() + size; z++) {
/*
* Algorithm:
* 1. Find lowest air block in the selection -> $lowestAir = position
* 2. Move the first non-air block above it down to $lowestAir
* 3. Add 1 to $lowestAir's y-coord.
* 4. If more blocks above current position, repeat from 2
*/
BlockVector3 lowestAir = null;
for (double y = position.getY() - size; y <= yMax; y++) { for (double y = position.getY() - size; y <= yMax; y++) {
BlockVector3 newPos = BlockVector3.at(x, y - 1, z);
BlockVector3 pt = BlockVector3.at(x, y, z); BlockVector3 pt = BlockVector3.at(x, y, z);
BaseBlock block = editSession.getFullBlock(pt); BaseBlock block = editSession.getFullBlock(pt);
if (block.getBlockType().getMaterial().isAir()) { if (block.getBlockType().getMaterial().isAir()) {
if (lowestAir == null) {
// we found the lowest air block
lowestAir = pt;
}
continue; continue;
} }
if (!removedBlocks.remove(newPos)) { if (lowestAir == null) {
// we have not moved the block below this one. // no place to move the block to
// is it free in the edit session? continue;
if (!editSession.getBlock(newPos).getBlockType().getMaterial().isAir()) {
// no -- do not move this block
continue;
}
} }
BlockVector3 newPos = lowestAir;
// we know the block above must be air,
// since either this block is being moved into it,
// or there has been more air before this block
lowestAir = lowestAir.add(0, 1, 0);
removedBlocks.remove(newPos);
column.add(newPos, block); column.add(newPos, block);
removedBlocks.add(pt); removedBlocks.add(pt);
} }