Add gmask multiple mask args + fix masked pattern

This commit is contained in:
Jesse Boyd 2016-09-28 23:10:34 +10:00
parent 76b4bb4857
commit 7da883b9d7
5 changed files with 241 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.blocks.BlockData;
import com.sk89q.worldedit.command.BrushCommands;
import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.FlattenedClipboardTransform;
import com.sk89q.worldedit.command.GeneralCommands;
import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.NavigationCommands;
import com.sk89q.worldedit.command.RegionCommands;
@ -350,6 +351,7 @@ public class Fawe {
NavigationCommands.inject(); // Translations + thru fix
ParametricBuilder.inject(); // Translations
ToolUtilCommands.inject(); // Fixes + Translations
GeneralCommands.inject(); // Translations + gmask args
// Schematic
SchematicReader.inject();
SchematicWriter.inject();

View File

@ -25,8 +25,9 @@ public class MaskedPattern extends AbstractPattern {
@Override
public BaseBlock apply(Vector position) {
patternExtent.setTarget(position);
if (mask.test(position)) {
return patternExtent.apply(position);
return patternExtent.getAndResetTarget();
}
return secondaryPattern.apply(position);
}

View File

@ -20,6 +20,7 @@ import javax.annotation.Nullable;
public class PatternExtent extends AbstractPattern implements Extent {
private final Pattern pattern;
private BaseBlock block;
private Vector target = new Vector();
public PatternExtent(Pattern pattern) {
this.pattern = pattern;
@ -53,13 +54,27 @@ public class PatternExtent extends AbstractPattern implements Extent {
@Override
public BaseBlock getBlock(Vector position) {
return block = pattern.apply(position);
BaseBlock tmp = pattern.apply(position);
if (position == target || (position.x == target.x && position.y == target.y && position.z == target.z)) {
block = tmp;
} else {
block = null;
}
return tmp;
}
public BaseBlock getAndResetBlock() {
public void setTarget(Vector vector) {
this.target = vector;
}
public BaseBlock getAndResetTarget() {
BaseBlock result = block;
block = null;
return result;
if (result != null) {
block = null;
return result;
} else {
return pattern.apply(target);
}
}
@Override

View File

@ -30,4 +30,4 @@ public class RandomOffsetPattern extends AbstractPattern {
mutable.z = position.z + r.nextInt(dz2) - dz;
return pattern.apply(mutable);
}
}
}

View File

@ -0,0 +1,217 @@
package com.sk89q.worldedit.command;
import com.boydti.fawe.config.BBC;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* General WorldEdit commands.
*/
public class GeneralCommands {
private final WorldEdit worldEdit;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public GeneralCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
}
@Command(
aliases = { "/limit" },
usage = "<limit>",
desc = "Modify block change limit",
min = 1,
max = 1
)
@CommandPermissions("worldedit.limit")
public void limit(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
int limit = Math.max(-1, args.getInteger(0));
if (!mayDisable && config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) {
player.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
return;
}
}
session.setBlockChangeLimit(limit);
if (limit != -1) {
player.print("Block change limit set to " + limit + ". (Use //limit -1 to go back to the default.)");
} else {
player.print("Block change limit set to " + limit + ".");
}
}
@Command(
aliases = { "/fast" },
usage = "[on|off]",
desc = "Toggle fast mode",
min = 0,
max = 1
)
@CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
String newState = args.getString(0, null);
if (session.hasFastMode()) {
if ("on".equals(newState)) {
player.printError("Fast mode already enabled.");
return;
}
session.setFastMode(false);
player.print("Fast mode disabled.");
} else {
if ("off".equals(newState)) {
player.printError("Fast mode already disabled.");
return;
}
session.setFastMode(true);
player.print("Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.");
}
}
@Command(
aliases = { "/gmask", "gmask" },
usage = "[mask]",
desc = "Set the global mask",
min = 0,
max = -1
)
@CommandPermissions("worldedit.global-mask")
public void gmask(Player player, LocalSession session, EditSession editSession, @Optional CommandContext context) throws WorldEditException {
if (context == null || context.argsLength() == 0) {
session.setMask((Mask) null);
BBC.BRUSH_MASK_DISABLED.send(player);
} else {
ParserContext parserContext = new ParserContext();
parserContext.setActor(player);
parserContext.setWorld(player.getWorld());
parserContext.setSession(session);
parserContext.setExtent(editSession);
Mask mask = worldEdit.getMaskFactory().parseFromInput(context.getJoinedStrings(0), parserContext);
session.setMask(mask);
BBC.BRUSH_MASK.send(player);
}
}
@Command(
aliases = { "/toggleplace", "toggleplace" },
usage = "",
desc = "Switch between your position and pos1 for placement",
min = 0,
max = 0
)
public void togglePlace(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
if (session.togglePlacementPosition()) {
player.print("Now placing at pos #1.");
} else {
player.print("Now placing at the block you stand in.");
}
}
@Command(
aliases = { "/searchitem", "/l", "/search", "searchitem" },
usage = "<query>",
flags = "bi",
desc = "Search for an item",
help =
"Searches for an item.\n" +
"Flags:\n" +
" -b only search for blocks\n" +
" -i only search for items",
min = 1,
max = 1
)
public void searchItem(Actor actor, CommandContext args) throws WorldEditException {
String query = args.getString(0).trim().toLowerCase();
boolean blocksOnly = args.hasFlag('b');
boolean itemsOnly = args.hasFlag('i');
try {
int id = Integer.parseInt(query);
ItemType type = ItemType.fromID(id);
if (type != null) {
actor.print("#" + type.getID() + " (" + type.getName() + ")");
} else {
actor.printError("No item found by ID " + id);
}
return;
} catch (NumberFormatException ignored) {
}
if (query.length() <= 2) {
actor.printError("Enter a longer search string (len > 2).");
return;
}
if (!blocksOnly && !itemsOnly) {
actor.print("Searching for: " + query);
} else if (blocksOnly && itemsOnly) {
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
return;
} else if (blocksOnly) {
actor.print("Searching for blocks: " + query);
} else {
actor.print("Searching for items: " + query);
}
int found = 0;
for (ItemType type : ItemType.values()) {
if (found >= 15) {
actor.print("Too many results!");
break;
}
if (blocksOnly && type.getID() > 255) {
continue;
}
if (itemsOnly && type.getID() <= 255) {
continue;
}
for (String alias : type.getAliases()) {
if (alias.contains(query)) {
actor.print("#" + type.getID() + " (" + type.getName() + ")");
++found;
break;
}
}
}
if (found == 0) {
actor.printError("No items found.");
}
}
public static Class<?> inject() {
return GeneralCommands.class;
}
}