Fix gravity brush expecting blocks to be set instantly

This commit is contained in:
Jesse Boyd 2016-04-30 17:07:37 +10:00
parent 19c0e03989
commit b9f2671166
2 changed files with 79 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.ScriptingCommands; import com.sk89q.worldedit.command.ScriptingCommands;
import com.sk89q.worldedit.command.composition.SelectionCommand; import com.sk89q.worldedit.command.composition.SelectionCommand;
import com.sk89q.worldedit.command.tool.brush.GravityBrush;
import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
@ -237,6 +238,8 @@ public class Fawe {
SchematicCommands.inject(); SchematicCommands.inject();
ScriptingCommands.inject(); ScriptingCommands.inject();
SelectionCommand.inject(); SelectionCommand.inject();
// Brushes
GravityBrush.inject();
// Visitors // Visitors
BreadthFirstSearch.inject(); BreadthFirstSearch.inject();
DownwardVisitor.inject(); DownwardVisitor.inject();

View File

@ -0,0 +1,76 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.function.pattern.Pattern;
public class GravityBrush implements Brush {
private final boolean fullHeight;
public GravityBrush(boolean fullHeight) {
this.fullHeight = fullHeight;
}
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException {
int size = (int) sizeDouble;
BaseBlock air = new BaseBlock(BlockID.AIR, 0);
int endY = position.getBlockY() + size;
int startPerformY = Math.max(0, position.getBlockY() - size);
int startCheckY = fullHeight ? 0 : startPerformY;
Vector mutablePos = new Vector(0, 0, 0);
for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
int freeSpot = startCheckY;
for (int y = startCheckY; y <= endY; y++) {
if (y < startPerformY) {
if (editSession.getLazyBlock(x, y, z) != EditSession.nullBlock) {
freeSpot = y + 1;
}
continue;
}
BaseBlock block = editSession.getLazyBlock(x, y, z);
if (block != EditSession.nullBlock) {
if (freeSpot != y) {
mutablePos.x = x;
mutablePos.y = freeSpot;
mutablePos.z = z;
editSession.setBlock(mutablePos, block);
mutablePos.y = y;
editSession.setBlock(mutablePos, EditSession.nullBlock);
}
freeSpot++;
}
}
}
}
}
public static Class<?> inject() {
return GravityBrush.class;
}
}