Fix gravity brush itself, not EditSession

Dieser Commit ist enthalten in:
Kenzie Togami 2019-07-06 00:12:17 -07:00
Ursprung f2c47f3759
Commit 3ad80665d8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
2 geänderte Dateien mit 43 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -565,12 +565,12 @@ public class EditSession implements Extent, AutoCloseable {
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
return bypassNone.getBlock(position); return world.getBlock(position);
} }
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return bypassNone.getFullBlock(position); return world.getFullBlock(position);
} }
/** /**

Datei anzeigen

@ -23,44 +23,62 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.util.LocatedBlock;
import com.sk89q.worldedit.util.collection.LocatedBlockList;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList; import java.util.LinkedHashSet;
import java.util.Collections; import java.util.Set;
import java.util.List;
public class GravityBrush implements Brush { public class GravityBrush implements Brush {
private final boolean fullHeight; private final boolean fullHeight;
public GravityBrush(boolean fullHeight) { public GravityBrush(boolean fullHeight) {
this.fullHeight = fullHeight; this.fullHeight = fullHeight;
} }
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size; double yMax = fullHeight ? editSession.getWorld().getMaxY() : position.getY() + size;
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { LocatedBlockList column = new LocatedBlockList();
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { Set<BlockVector3> removedBlocks = new LinkedHashSet<>();
double y = startY; for (double x = position.getX() - size; x <= position.getX() + size; x++) {
final List<BlockState> blockTypes = new ArrayList<>(); for (double z = position.getZ() - size; z <= position.getZ() + size; z++) {
for (; y > position.getBlockY() - size; --y) { for (double y = position.getY() - size; y <= yMax; y++) {
final BlockVector3 pt = BlockVector3.at(x, y, z); BlockVector3 newPos = BlockVector3.at(x, y - 1, z);
final BlockState block = editSession.getBlock(pt); BlockVector3 pt = BlockVector3.at(x, y, z);
if (!block.getBlockType().getMaterial().isAir()) {
blockTypes.add(block); BaseBlock block = editSession.getFullBlock(pt);
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
if (block.getBlockType().getMaterial().isAir()) {
continue;
} }
}
BlockVector3 pt = BlockVector3.at(x, y, z); if (!removedBlocks.remove(newPos)) {
Collections.reverse(blockTypes); // we have not moved the block below this one.
for (int i = 0; i < blockTypes.size();) { // is it free in the edit session?
if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) { if (!editSession.getBlock(newPos).getBlockType().getMaterial().isAir()) {
editSession.setBlock(pt, blockTypes.get(i++)); // no -- do not move this block
continue;
}
} }
pt = pt.add(0, 1, 0);
column.add(newPos, block);
removedBlocks.add(pt);
} }
for (LocatedBlock block : column) {
editSession.setBlock(block.getLocation(), block.getBlock());
}
for (BlockVector3 removedBlock : removedBlocks) {
editSession.setBlock(removedBlock, BlockTypes.AIR.getDefaultState());
}
column.clear();
removedBlocks.clear();
} }
} }
} }