Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an AdjacentMask, with a parser for an Exposed/Surface mask
- Loading branch information
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...re/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExposedMaskParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.WorldEdit; | ||
import com.sk89q.worldedit.extension.input.InputParseException; | ||
import com.sk89q.worldedit.extension.input.ParserContext; | ||
import com.sk89q.worldedit.function.mask.AdjacentMask; | ||
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; | ||
|
||
import java.util.List; | ||
|
||
public class ExposedMaskParser extends SimpleInputParser<Mask> { | ||
|
||
private final List<String> aliases = ImmutableList.of("#exposed", "#surface"); | ||
|
||
public ExposedMaskParser(WorldEdit worldEdit) { | ||
super(worldEdit); | ||
} | ||
|
||
@Override | ||
public List<String> getMatchedAliases() { | ||
return this.aliases; | ||
} | ||
|
||
@Override | ||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException { | ||
return new AdjacentMask(Masks.negate(new ExistingBlockMask(context.requireExtent())), true); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AdjacentMask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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.google.common.collect.ImmutableList; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
import com.sk89q.worldedit.util.Direction; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Checks whether any face of the given position is adjacent to a block matching a given mask. | ||
*/ | ||
public class AdjacentMask extends AbstractMask { | ||
|
||
private static final List<Direction> DIRECTION_LIST = ImmutableList.copyOf( | ||
Direction.valuesOf(Direction.Flag.CARDINAL | Direction.Flag.UPRIGHT) | ||
); | ||
|
||
private final Mask mask; | ||
private final boolean excludeSelf; | ||
|
||
/** | ||
* Create a new instance. | ||
* | ||
* @param mask the mask to test against | ||
* @param excludeSelf excludes blocks where the mask matches itself | ||
*/ | ||
public AdjacentMask(Mask mask, boolean excludeSelf) { | ||
this.mask = mask; | ||
this.excludeSelf = excludeSelf; | ||
} | ||
|
||
@Override | ||
public boolean test(BlockVector3 vector) { | ||
if (excludeSelf && mask.test(vector)) { | ||
return false; | ||
} | ||
for (Direction direction : DIRECTION_LIST) { | ||
if (mask.test(vector.add(direction.toBlockVector()))) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Mask2D toMask2D() { | ||
return null; | ||
} | ||
} |