Add some more __internal__ <-> air logi

Fixes #831
This commit is contained in:
dordsor21 2021-01-06 16:40:28 +00:00
parent 336b90be15
commit e40e86df5f
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
9 changed files with 56 additions and 5 deletions

View File

@ -16,4 +16,9 @@ public class AirMask extends BlockMask {
return new AirMask(getExtent());
}
@Override
public boolean replacesAir() {
return true;
}
}

View File

@ -37,4 +37,9 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask {
return new IdDataMask(getExtent());
}
@Override
public boolean replacesAir() {
return true;
}
}

View File

@ -38,4 +38,9 @@ public class IdMask extends AbstractExtentMask implements ResettableMask {
return new IdMask(getExtent());
}
@Override
public boolean replacesAir() {
return true;
}
}

View File

@ -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);
}
}

View File

@ -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<BlockState> 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);
}

View File

@ -36,4 +36,9 @@ public class InverseMask extends AbstractMask {
public Mask copy() {
return new InverseMask(mask.copy());
}
@Override
public boolean replacesAir() {
return mask.replacesAir();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -118,4 +118,14 @@ public class MaskUnion extends MaskIntersection {
Set<Mask> 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;
}
}