Skip to content

Commit

Permalink
Add a #match mask, to mask to blocks that match the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Apr 4, 2024
1 parent 79a06b1 commit d530fe4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@
import com.sk89q.worldedit.extension.factory.parser.mask.ExposedMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.MatchMaskParser;
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;
Expand Down Expand Up @@ -65,6 +66,7 @@ public final class MaskFactory extends AbstractFactory<Mask> {
public MaskFactory(WorldEdit worldEdit) {
super(worldEdit, new BlocksMaskParser(worldEdit));

register(new MatchMaskParser(worldEdit));
register(new ExistingMaskParser(worldEdit));
register(new AirMaskParser(worldEdit));
register(new ExposedMaskParser(worldEdit));
Expand Down
@@ -0,0 +1,55 @@
/*
* 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 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 <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.extension.factory.parser.mask;

import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MatchMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;

import java.util.List;

public class MatchMaskParser extends SimpleInputParser<Mask> {

private final List<String> aliases = ImmutableList.of("#match");

public MatchMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}

@Override
public List<String> getMatchedAliases() {
return aliases;
}

@Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
try {
return new MatchMask(context.requireExtent(), context.requireSession().getClipboard().getClipboard());
} catch (EmptyClipboardException e) {
throw new InputParseException(TranslatableComponent.of("worldedit.error.empty-clipboard"));
}
}
}
@@ -0,0 +1,45 @@
/*
* 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 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 <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.function.mask;

import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;

public class MatchMask extends AbstractMask {

private final Extent extent;
private final Extent matchExtent;
private final BlockVector3 offset;

public MatchMask(Extent extent, Extent matchExtent) {
this(extent, matchExtent, BlockVector3.ZERO);
}

public MatchMask(Extent extent, Extent matchExtent, BlockVector3 offset) {
this.extent = extent;
this.matchExtent = matchExtent;
this.offset = offset;
}

@Override
public boolean test(BlockVector3 vector) {
return extent.getBlock(vector).equals(matchExtent.getBlock(vector.add(offset)));
}
}

0 comments on commit d530fe4

Please sign in to comment.