New masks

This commit is contained in:
MattBDev 2020-03-17 22:20:58 -04:00
parent 85b65669bd
commit ecedc1ff12
17 changed files with 201 additions and 85 deletions

View File

@ -0,0 +1,39 @@
/*
* 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.boydti.fawe.function.mask;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask2D;
import javax.annotation.Nullable;
public class AirMask extends BlockMask {
public AirMask(Extent extent) {
super(extent);
add(state -> state.getMaterial().isAir());
}
@Nullable
@Override
public Mask2D toMask2D() {
return null;
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.boydti.fawe.function.mask;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.math.BlockVector3;
import javax.annotation.Nullable;
public class LiquidMask extends BlockMask {
public LiquidMask(Extent extent) {
super(extent);
add(state -> state.getMaterial().isLiquid());
}
@Nullable
@Override
public Mask2D toMask2D() {
return null;
}
}

View File

@ -4,9 +4,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractMask;
import com.sk89q.worldedit.math.BlockVector3;
/**
* Restricts the
*/
public class PlaneMask extends AbstractMask implements ResettableMask {
private transient int mode = -1;

View File

@ -4,9 +4,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractMask;
import com.sk89q.worldedit.math.BlockVector3;
/**
* Restricts the
*/
public class XAxisMask extends AbstractMask implements ResettableMask {
private transient int layer = -1;

View File

@ -4,9 +4,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractMask;
import com.sk89q.worldedit.math.BlockVector3;
/**
* Restricts the
*/
public class YAxisMask extends AbstractMask implements ResettableMask {
private transient int layer = -1;

View File

@ -4,9 +4,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractMask;
import com.sk89q.worldedit.math.BlockVector3;
/**
* Restricts the
*/
public class ZAxisMask extends AbstractMask implements ResettableMask {
private transient int layer = -1;

View File

@ -122,14 +122,6 @@
// }
//
// @Command(
// name = "#offset",
// desc = "Offset a mask"
// )
// public Mask offset(@Arg(desc = "double x") double x, @Arg(desc = "double y") double y, @Arg(desc = "double z") double z, @Arg(desc = "Mask") Mask mask) {
// return new OffsetMask(mask, BlockVector3.at(x, y, z));
// }
//
// @Command(
// name = "#haslight",
// desc = "Restricts to blocks with light (sky or emitted)"
// )
@ -146,23 +138,6 @@
// }
//
// @Command(
// name = "#liquid",
// desc = "If there is a solid block"
// )
// public Mask liquid(Extent extent) {
// return new BlockMaskBuilder().addAll(b -> b.getMaterial().isLiquid()).build(extent);
// }
//
// @Command(
// name = "#dregion",
// aliases = {"#dselection", "#dsel"},
// desc = "inside the player's selection"
// )
// public Mask dregion() {
// return new RegionMask(new RequestSelection());
// }
//
// @Command(
// name = "#region",
// aliases = {"#selection", "#sel"},
// desc = "inside the provided selection"
@ -220,14 +195,6 @@
// }
//
// @Command(
// name = "#air",
// desc = "Restrict to types of air"
// )
// public Mask air(Extent extent) {
// return new BlockMaskBuilder().addAll(b -> b.getMaterial().isAir()).build(extent);
// }
//
// @Command(
// name = "#wall",
// desc = "Restrict to walls (any block n,e,s,w of air)"
// )

View File

@ -570,7 +570,6 @@ public class SelectionCommands {
public void select(Actor actor, World world, LocalSession session,
@Arg(desc = "Selector to switch to", def = "")
SelectorChoice selector,
@Arg(desc = "Selector mask") Mask maskOpt,
@Switch(name = 'd', desc = "Set default selector")
boolean setDefaultSelector) throws WorldEditException {
if (selector == null) {
@ -624,14 +623,12 @@ public class SelectionCommands {
newSelector = new PolyhedralRegionSelector(world);
actor.print(TranslatableComponent.of("fawe.selection.sel.convex.polyhedral"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", (integer))));
limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
actor.print(TranslatableComponent.of("fawe.selection.sel.list"));
break;
case FUZZY:
case MAGIC:
if (maskOpt == null) {
maskOpt = new IdMask(world);
}
Mask maskOpt = new IdMask(world);
//TODO Make FuzzyRegionSelector accept actors
newSelector = new FuzzyRegionSelector((Player) actor, world, maskOpt);
actor.print(TranslatableComponent.of("fawe.selection.sel.fuzzy"));

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser;
@ -28,6 +29,7 @@ import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
@ -77,6 +79,8 @@ public final class MaskFactory extends AbstractFactory<Mask> {
// Mask Parsers from FAWE
register(new FalseMaskParser(worldEdit));
register(new TrueMaskParser(worldEdit));
register(new AirMaskParser(worldEdit));
register(new LiquidMaskParser(worldEdit));
}

View File

@ -0,0 +1,48 @@
/*
* 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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.AirMask;
import com.boydti.fawe.function.mask.LiquidMask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class AirMaskParser extends SimpleInputParser<Mask> {
private final List<String> aliases = ImmutableList.of("#air");
public AirMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return aliases;
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new AirMask(context.getExtent());
}
}

View File

@ -3,7 +3,6 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;

View File

@ -0,0 +1,49 @@
/*
* 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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.LiquidMask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class LiquidMaskParser extends SimpleInputParser<Mask> {
private final List<String> aliases = ImmutableList.of("#liquid");
public LiquidMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return aliases;
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new LiquidMask(context.getExtent());
}
}

View File

@ -3,7 +3,6 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;

View File

@ -559,12 +559,6 @@ public final class PlatformCommandManager {
void registerCommandsWith(Platform platform) {
log.info("Registering commands with " + platform.getClass().getCanonicalName());
// Delay command registration to allow time for other plugins to hook into FAWE
try {
// new CommandScriptLoader().load();
} catch (Throwable e) {
e.printStackTrace();
}
LocalConfiguration config = platform.getConfiguration();
boolean logging = config.logCommands;

View File

@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.util.ArrayList;

View File

@ -32,6 +32,7 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import javax.annotation.Nullable;
@ -71,7 +72,7 @@ public class BlockMask extends ABlockMask {
public BlockMask(Extent extent, Collection<BaseBlock> blocks) {
this(extent);
checkNotNull(blocks);
add(blocks);
this.add(blocks);
}
/**
@ -166,6 +167,14 @@ public class BlockMask extends ABlockMask {
add(Arrays.asList(checkNotNull(block)));
}
/**
* Get the list of blocks that are tested with.
*
* @return a list of blocks
*/
public Collection<BaseBlock> getBlocks() {
return Collections.emptyList(); //TODO Not supported in FAWE yet
}
@Override
public boolean test(BlockState state) {
return ordinals[state.getOrdinal()];

View File

@ -33,39 +33,22 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}.
* @deprecated let the queue iterate, not the region function which lacks any kind of optimizations / parallelism
* @deprecated Let the queue iterate, not the region function which lacks any kind of optimizations / parallelism
*/
@Deprecated
public class RegionVisitor implements Operation {
public final Region region;
public final RegionFunction function;
public int affected = 0;
public final Iterable<? extends BlockVector3> iterable;
private final Region region;
private final RegionFunction function;
private int affected = 0;
/**
* Deprecated in favor of the other constructors which will preload chunks during iteration
*
* @param region
* @param function
* @deprecated Use other constructors which will preload chunks during iteration
*/
@Deprecated
public RegionVisitor(Region region, RegionFunction function) {
this((Iterable<BlockVector3>) region, function);
}
/**
* Deprecated in favor of the other constructors which will preload chunks during iteration
*
* @param iterable
* @param function
*/
@Deprecated
public RegionVisitor(Iterable<BlockVector3> iterable, RegionFunction function) {
this.region = iterable instanceof Region ? (Region) iterable : null;
this.region = region;
this.function = function;
this.iterable = iterable;
}
/**
@ -79,7 +62,7 @@ public class RegionVisitor implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
for (BlockVector3 pt : iterable) {
for (BlockVector3 pt : region) {
if (function.apply(pt)) {
affected++;
}
@ -97,7 +80,7 @@ public class RegionVisitor implements Operation {
return ImmutableList.of(TranslatableComponent.of(
"worldedit.operation.affected.block",
TextComponent.of(getAffected())
).color(TextColor.GRAY));
).color(TextColor.LIGHT_PURPLE));
}
}