Some pattern fixes

This commit is contained in:
Jesse Boyd 2017-03-12 03:09:40 +11:00
parent 8c4ed29edb
commit 503cb7f108
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
8 changed files with 96 additions and 61 deletions

View File

@ -4,39 +4,65 @@ import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.example.NMSRelighter;
import com.boydti.fawe.object.*;
import com.boydti.fawe.object.FaweLocation;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.object.mask.CustomMask;
import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.*;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.jnbt.*;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.extension.factory.DefaultMaskParser;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.World;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.*;
import java.util.zip.Deflater;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

View File

@ -97,8 +97,6 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.function.util.RegionOffset;
import com.sk89q.worldedit.function.visitor.DownwardVisitor;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
@ -116,6 +114,7 @@ import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.math.interpolation.Node;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.EllipsoidRegion;
import com.sk89q.worldedit.regions.FlatRegion;
@ -1109,7 +1108,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
public boolean setBlock(int x, int y, int z, Pattern pattern) {
this.changes++;
try {
return this.extent.setBlock(x, y, z, pattern.apply(x, y, z));
return this.extent.setBlock(x, y, z, pattern.next(x, y, z));
} catch (WorldEditException e) {
throw new RuntimeException("Unexpected exception", e);
}
@ -1648,10 +1647,6 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
return changes;
}
public int setBlocks(final Region region, final com.sk89q.worldedit.patterns.Pattern pattern) throws MaxChangedBlocksException {
return setBlocks(region, Patterns.wrap(pattern));
}
/**
* Sets all the blocks inside a region to a given pattern.
*
@ -3070,7 +3065,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
final int tipy = (int) Math.round(tipv.getY());
final int tipz = (int) Math.round(tipv.getZ());
if (radius == 0) {
setBlock(tipx, tipy, tipz, pattern.apply(tipx, tipy, tipz));
setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz));
} else {
vset.add(new Vector(tipx, tipy, tipz));
}

View File

@ -58,6 +58,40 @@ public class HashTagPatternParser extends FaweParser<Pattern> {
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (input.isEmpty()) {
throw new SuggestInputParseException(input, ALL_PATTERNS);
}
List<String> items = StringMan.split(input, ',');
if (items.size() == 1) {
return parseSinglePatternFromInput(items.get(0), context);
}
RandomPattern randomPattern = new RandomPattern();
try {
for (String token : items) {
Pattern pattern;
double chance;
// Parse special percentage syntax
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
String[] p = token.split("%");
if (p.length < 2) {
throw new InputParseException("Missing the pattern after the % symbol for '" + input + "'");
} else {
chance = Expression.compile(p[0]).evaluate();
pattern = catchSuggestion(input, p[1], context);
}
} else {
chance = 1;
pattern = catchSuggestion(input, token, context);
}
randomPattern.add(pattern, chance);
}
} catch (NumberFormatException | ExpressionException e) {
throw new InputParseException("Invalid, see: https://github.com/boy0001/FastAsyncWorldedit/wiki/WorldEdit-and-FAWE-patterns");
}
return randomPattern;
}
public Pattern parseSinglePatternFromInput(String input, ParserContext context) throws InputParseException {
if (input.isEmpty()) {
throw new SuggestInputParseException(input, ALL_PATTERNS);
}

View File

@ -23,7 +23,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.patterns.Pattern;
import static com.google.common.base.Preconditions.checkNotNull;
@ -49,6 +49,10 @@ public class BlockReplace implements RegionFunction {
this.pattern = pattern;
}
public BlockReplace(Extent extent, com.sk89q.worldedit.function.pattern.Pattern pattern) {
this(extent, (Pattern) pattern);
}
@Override
public boolean apply(Vector position) throws WorldEditException {
return pattern.apply(extent, position);

View File

@ -6,7 +6,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import static com.google.common.base.Preconditions.checkNotNull;
public class BlockPattern extends AbstractPattern {
public class BlockPattern implements Pattern {
private BaseBlock block;

View File

@ -21,14 +21,12 @@ package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent;
/**
* Returns a {@link BaseBlock} for a given position.
*/
public interface Pattern {
public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{
/**
* Return a {@link BaseBlock} for the given position.
@ -42,8 +40,14 @@ public interface Pattern {
return apply(MutableBlockVector.get(x, y, z));
}
default boolean apply(Extent extent,Vector position) throws WorldEditException {
return extent.setBlock(position, apply(position));
@Override
default BaseBlock next(Vector position) {
return apply(position);
}
@Override
default BaseBlock next(int x, int y, int z) {
return apply(x, y, z);
}
public static Class<Pattern> inject() {

View File

@ -1,9 +1,5 @@
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Utility methods related to {@link Pattern}s.
*/
@ -19,7 +15,10 @@ public final class Patterns {
* @return a new-style pattern
*/
public static Pattern wrap(final com.sk89q.worldedit.patterns.Pattern pattern) {
return pattern;
if (pattern instanceof Pattern) {
return (Pattern) pattern;
}
return position -> pattern.next(position);
}
/**
@ -29,24 +28,7 @@ public final class Patterns {
* @return an old-style pattern
*/
public static com.sk89q.worldedit.patterns.Pattern wrap(final Pattern pattern) {
if (pattern instanceof com.sk89q.worldedit.patterns.Pattern) {
return (com.sk89q.worldedit.patterns.Pattern) pattern;
}
return new com.sk89q.worldedit.patterns.Pattern() {
private MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
@Override
public BaseBlock next(Vector position) {
return pattern.apply(position);
}
@Override
public BaseBlock next(int x, int y, int z) {
mutable.mutX(x);
mutable.mutY(y);
mutable.mutZ(z);
return next(mutable);
}
};
return pattern;
}
public static Class<?> inject() {

View File

@ -19,7 +19,8 @@
package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent;
@ -27,7 +28,7 @@ import com.sk89q.worldedit.extent.Extent;
* @deprecated See {@link com.sk89q.worldedit.function.pattern.Pattern}
*/
@Deprecated
public interface Pattern extends com.sk89q.worldedit.function.pattern.Pattern{
public interface Pattern{
/**
* Get a block for a position. This return value of this method does
@ -38,19 +39,8 @@ public interface Pattern extends com.sk89q.worldedit.function.pattern.Pattern{
*/
public BaseBlock next(Vector position);
@Override
default boolean apply(Extent extent, Vector position) throws WorldEditException {
return extent.setBlock(position, apply(position));
}
@Override
default BaseBlock apply(Vector position) {
return next(position);
}
@Override
default BaseBlock apply(int x, int y, int z) {
return next(x, y, z);
return extent.setBlock(position, next(position));
}
/**