Reimplement radius mask, fix wall mask

This commit is contained in:
dordsor21 2021-08-17 17:03:25 +01:00
parent 46f6395279
commit 569fdc3861
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 37 additions and 18 deletions

View File

@ -20,14 +20,14 @@ public class RadiusMaskParser extends RichParser<Mask> {
@Override @Override
protected Stream<String> getSuggestions(String argumentInput, int index) { protected Stream<String> getSuggestions(String argumentInput, int index) {
if (index == 0 || index == 1) { if (index == 0 || index == 1) {
return SuggestionHelper.suggestPositiveDoubles(argumentInput); return SuggestionHelper.suggestPositiveIntegers(argumentInput);
} }
return Stream.empty(); return Stream.empty();
} }
@Override @Override
protected Mask parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException { protected Mask parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length < 2) { if (arguments.length != 2) {
return null; return null;
} }
int min = Integer.parseInt(arguments[0]); int min = Integer.parseInt(arguments[0]);

View File

@ -1,22 +1,21 @@
package com.fastasyncworldedit.core.extension.factory.parser.mask; package com.fastasyncworldedit.core.extension.factory.parser.mask;
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
import com.fastasyncworldedit.core.function.mask.WallMask; import com.fastasyncworldedit.core.function.mask.WallMask;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.SuggestionHelper;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
public class WallMaskParser extends SimpleInputParser<Mask> { public class WallMaskParser extends RichParser<Mask> {
private final List<String> aliases = ImmutableList.of("#wall"); private final List<String> aliases = ImmutableList.of("#wall", "|");
public WallMaskParser(WorldEdit worldEdit) { public WallMaskParser(WorldEdit worldEdit) {
super(worldEdit); super(worldEdit);
@ -28,11 +27,30 @@ public class WallMaskParser extends SimpleInputParser<Mask> {
} }
@Override @Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException { protected Stream<String> getSuggestions(final String argumentInput, final int index) {
return new MaskIntersection( if (index == 0) {
new ExistingBlockMask(context.getExtent()), return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
new WallMask(new BlockMask(context.getExtent(), BlockTypes.AIR.getDefaultState().toBaseBlock()), 1, 8) } else if (index == 1 || index == 2) {
); return SuggestionHelper.suggestPositiveDoubles(argumentInput);
}
return Stream.empty();
}
@Override
protected Mask parseFromInput(@Nonnull final String[] arguments, final ParserContext context) throws InputParseException {
if (arguments.length > 3 || arguments.length == 0) {
return null;
}
Mask subMask = worldEdit.getMaskFactory().parseFromInput(arguments[0], context);
int min = arguments.length > 1 ? Integer.parseInt(arguments[1]) : -1;
int max = arguments.length > 2 ? Integer.parseInt(arguments[2]) : -1;
if (min == -1 && max == -1) {
min = 1;
max = 8;
} else if (max == -1) {
max = min;
}
return new WallMask(subMask, min, max);
} }
} }

View File

@ -6,9 +6,9 @@ import com.sk89q.worldedit.math.BlockVector3;
public class RadiusMask extends AbstractMask implements ResettableMask { public class RadiusMask extends AbstractMask implements ResettableMask {
private transient BlockVector3 pos;
private final int minSqr; private final int minSqr;
private final int maxSqr; private final int maxSqr;
private transient BlockVector3 pos;
public RadiusMask(int min, int max) { public RadiusMask(int min, int max) {
this.minSqr = min * min; this.minSqr = min * min;
@ -47,7 +47,7 @@ public class RadiusMask extends AbstractMask implements ResettableMask {
@Override @Override
public Mask copy() { public Mask copy() {
return new RadiusMask(minSqr, maxSqr); return new RadiusMask((Integer) minSqr, (Integer) maxSqr);
} }
} }

View File

@ -22,11 +22,12 @@ package com.sk89q.worldedit.extension.factory;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.mask.AdjacentMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.AdjacentMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.AngleMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.AngleMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.RichMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.ExtremaMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.ExtremaMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.FalseMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.FalseMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.LiquidMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.LiquidMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.ROCAngleMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.ROCAngleMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.RadiusMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.RichMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.RichOffsetMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.RichOffsetMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.SimplexMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.SimplexMaskParser;
import com.fastasyncworldedit.core.extension.factory.parser.mask.SurfaceAngleMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.SurfaceAngleMaskParser;
@ -108,7 +109,7 @@ public final class MaskFactory extends AbstractFactory<Mask> {
register(new ExtremaMaskParser(worldEdit)); register(new ExtremaMaskParser(worldEdit));
register(new FalseMaskParser(worldEdit)); register(new FalseMaskParser(worldEdit));
register(new LiquidMaskParser(worldEdit)); register(new LiquidMaskParser(worldEdit));
//register(new RadiusMaskParser(worldEdit)); TODO: Adapt to work with FAWE's Chunk I/O register(new RadiusMaskParser(worldEdit));
register(new RichOffsetMaskParser(worldEdit)); register(new RichOffsetMaskParser(worldEdit));
register(new ROCAngleMaskParser(worldEdit)); register(new ROCAngleMaskParser(worldEdit));
register(new SimplexMaskParser(worldEdit)); register(new SimplexMaskParser(worldEdit));