3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 21:10:05 +01:00

Added flood fill tool, fixed data values not being set properly.

Dieser Commit ist enthalten in:
sk89q 2011-06-04 19:41:12 -07:00
Ursprung 730244056c
Commit 0f040429c5
4 geänderte Dateien mit 151 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -290,6 +290,11 @@ commands:
description: Block data cycler tool description: Block data cycler tool
usage: /<command> usage: /<command>
permissions: 'worldedit.tool.data-cycler' permissions: 'worldedit.tool.data-cycler'
floodfill:
description: Flood fill tool
usage: /<command>
aliases: ['flood']
permissions: 'worldedit.tool.flood-fill'
brush: brush:
description: Brush tool description: Brush tool
usage: /<command> usage: /<command>

Datei anzeigen

@ -215,7 +215,7 @@ public class EditSession {
} }
if (id != 0) { if (id != 0) {
if (existing != type && block.getData() > 0 && BlockType.usesData(id)) { if (BlockType.usesData(id)) {
if (fastMode) { if (fastMode) {
world.setBlockDataFast(pt, block.getData()); world.setBlockDataFast(pt, block.getData());
} else { } else {

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.tools.*; import com.sk89q.worldedit.tools.*;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
@ -123,6 +124,32 @@ public class ToolCommands {
+ ItemType.toHeldName(player.getItemInHand()) + "."); + ItemType.toHeldName(player.getItemInHand()) + ".");
} }
@Command(
aliases = {"floodfill", "flood"},
usage = "",
desc = "Flood fill tool",
min = 2,
max = 2
)
@CommandPermissions({"worldedit.tool.flood-fill"})
public static void floodFill(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(1);
if (range > config.maxSuperPickaxeSize) {
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
return;
}
Pattern pattern = we.getBlockPattern(player, args.getString(0));
session.setTool(player.getItemInHand(), new FloodFillTool(range, pattern));
player.print("Block flood fill tool bound to "
+ ItemType.toHeldName(player.getItemInHand()) + ".");
}
@Command( @Command(
aliases = {"brush", "br"}, aliases = {"brush", "br"},
desc = "Brush tool" desc = "Brush tool"

Datei anzeigen

@ -0,0 +1,118 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.patterns.Pattern;
/**
* A tool that flood fills blocks.
*
* @author sk89q
*/
public class FloodFillTool implements BlockTool {
private int range;
private Pattern pattern;
public FloodFillTool(int range, Pattern pattern) {
this.range = range;
this.pattern = pattern;
}
public boolean canUse(LocalPlayer player) {
return player.hasPermission("worldedit.tool.flood-fill");
}
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();
int initialType = world.getBlockType(clicked);
if (initialType == 0) {
return true;
}
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
EditSession editSession = session.createEditSession(player);
try {
recurse(server, editSession, world, clicked.toBlockVector(),
clicked, range, initialType, new HashSet<BlockVector>());
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
return true;
}
/**
* Helper method.
*
* @param server
* @param superPickaxeManyDrop
* @param world
* @param pos
* @param origin
* @param size
* @param initialType
* @param visited
*/
private void recurse(ServerInterface server, EditSession editSession,
LocalWorld world, BlockVector pos,
Vector origin, int size, int initialType,
Set<BlockVector> visited)
throws MaxChangedBlocksException {
if (origin.distance(pos) > size || visited.contains(pos)) {
return;
}
visited.add(pos);
if (editSession.getBlock(pos).getType() == initialType) {
editSession.setBlock(pos, pattern.next(pos));
} else {
return;
}
recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
origin, size, initialType, visited);
}
}