From e40e86df5f0dc8ab8eeea6de56463253d39bd43f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 6 Jan 2021 16:40:28 +0000 Subject: [PATCH] Add some more __internal__ <-> air logi Fixes #831 --- .../main/java/com/boydti/fawe/object/mask/AirMask.java | 5 +++++ .../java/com/boydti/fawe/object/mask/IdDataMask.java | 5 +++++ .../main/java/com/boydti/fawe/object/mask/IdMask.java | 5 +++++ .../worldedit/function/mask/BlockCategoryMask.java | 6 ++++++ .../com/sk89q/worldedit/function/mask/BlockMask.java | 8 +++----- .../com/sk89q/worldedit/function/mask/InverseMask.java | 5 +++++ .../function/mask/InverseSingleBlockTypeMask.java | 7 +++++++ .../worldedit/function/mask/MaskIntersection.java | 10 ++++++++++ .../com/sk89q/worldedit/function/mask/MaskUnion.java | 10 ++++++++++ 9 files changed, 56 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AirMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AirMask.java index 950f1d9df..69f1bf9c2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AirMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AirMask.java @@ -16,4 +16,9 @@ public class AirMask extends BlockMask { return new AirMask(getExtent()); } + @Override + public boolean replacesAir() { + return true; + } + } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java index 0329f0b5c..105af3965 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java @@ -37,4 +37,9 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask { return new IdDataMask(getExtent()); } + @Override + public boolean replacesAir() { + return true; + } + } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java index 6528d5407..ebb2f5d9b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java @@ -38,4 +38,9 @@ public class IdMask extends AbstractExtentMask implements ResettableMask { return new IdMask(getExtent()); } + @Override + public boolean replacesAir() { + return true; + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java index e600929b3..a38a77e04 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategory; +import com.sk89q.worldedit.world.block.BlockTypes; import javax.annotation.Nullable; @@ -61,4 +62,9 @@ public class BlockCategoryMask extends AbstractExtentMask { public Mask copy() { return new BlockCategoryMask(getExtent(), category); } + + @Override + public boolean replacesAir() { + return category.contains(BlockTypes.AIR); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index 665415618..efe910dd3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -29,12 +29,12 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.ImmutableBaseBlock; +import javax.annotation.Nullable; 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; import static com.google.common.base.Preconditions.checkNotNull; @@ -185,7 +185,7 @@ public class BlockMask extends ABlockMask { @Override public boolean test(BlockState state) { - return ordinals[state.getOrdinal()] || replacesAir() && state.getOrdinal() <= 3; + return ordinals[state.getOrdinal()] || replacesAir() && state.getOrdinal() == 0; } @Override @@ -259,19 +259,16 @@ public class BlockMask extends ABlockMask { int setTypes = 0; BlockType setType = null; - BlockType unsetType = null; int totalTypes = 0; for (BlockType type : BlockTypesCache.values) { if (type != null) { totalTypes++; boolean hasAll = true; - boolean hasAny = false; List all = type.getAllStates(); for (BlockState state : all) { totalStates++; hasAll &= test(state); - hasAny = true; } if (hasAll) { setTypes++; @@ -326,6 +323,7 @@ public class BlockMask extends ABlockMask { cloned[BlockTypes.AIR.getDefaultState().getOrdinal()] = false; cloned[BlockTypes.CAVE_AIR.getDefaultState().getOrdinal()] = false; cloned[BlockTypes.VOID_AIR.getDefaultState().getOrdinal()] = false; + cloned[0] = false; } return new BlockMask(getExtent(), cloned); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java index ed86f6bc0..2389eb981 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java @@ -36,4 +36,9 @@ public class InverseMask extends AbstractMask { public Mask copy() { return new InverseMask(mask.copy()); } + + @Override + public boolean replacesAir() { + return mask.replacesAir(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java index fa6da2278..a8dcd3c18 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java @@ -8,10 +8,12 @@ import com.sk89q.worldedit.world.block.BlockTypesCache; public class InverseSingleBlockTypeMask extends ABlockMask { private final int internalId; + private final boolean replacesAir; public InverseSingleBlockTypeMask(Extent extent, BlockType type) { super(extent); this.internalId = type.getInternalId(); + this.replacesAir = type.getMaterial().isAir(); } @Override @@ -33,4 +35,9 @@ public class InverseSingleBlockTypeMask extends ABlockMask { // The mask is not mutable. There is no need to clone it. return this; } + + @Override + public boolean replacesAir() { + return replacesAir; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index 2b3968744..ab8b95b0b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -275,4 +275,14 @@ public class MaskIntersection extends AbstractMask { return new MaskIntersection(masks); } + @Override + public boolean replacesAir() { + for (Mask mask : masksArray) { + if (mask.replacesAir()) { + return true; + } + } + return false; + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java index 25174efd6..4adf197de 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java @@ -118,4 +118,14 @@ public class MaskUnion extends MaskIntersection { Set masksCopy = masks.stream().map(Mask::copy).collect(Collectors.toSet()); return new MaskUnion(masksCopy); } + + @Override + public boolean replacesAir() { + for (Mask mask : getMasksArray()) { + if (mask.replacesAir()) { + return true; + } + } + return false; + } }