Search in sources :

Example 1 with SingleBlockStateMask

use of com.fastasyncworldedit.core.function.mask.SingleBlockStateMask in project FastAsyncWorldEdit by IntellectualSites.

the class BlockMask method tryOptimize.

@Override
public Mask tryOptimize() {
    int setStates = 0;
    BlockState setState = null;
    BlockState unsetState = null;
    int totalStates = 0;
    int setTypes = 0;
    BlockType setType = null;
    int totalTypes = 0;
    for (BlockType type : BlockTypesCache.values) {
        if (type != null) {
            totalTypes++;
            boolean hasAll = true;
            List<BlockState> all = type.getAllStates();
            for (BlockState state : all) {
                totalStates++;
                hasAll &= test(state);
            }
            if (hasAll) {
                setTypes++;
                setType = type;
                setStates += all.size();
                setState = type.getDefaultState();
            } else {
                for (BlockState state : all) {
                    if (test(state)) {
                        setStates++;
                        setState = state;
                    } else {
                        unsetState = state;
                    }
                }
            }
        }
    }
    if (setStates == 0) {
        return Masks.alwaysFalse();
    }
    if (setStates == totalStates) {
        return Masks.alwaysTrue();
    }
    if (setStates == 1) {
        return new SingleBlockStateMask(getExtent(), setState);
    }
    if (setStates == totalStates - 1) {
        return new InverseSingleBlockStateMask(getExtent(), unsetState);
    }
    if (setTypes == 1) {
        return new SingleBlockTypeMask(getExtent(), setType);
    }
    if (setTypes == totalTypes - 1) {
        throw new IllegalArgumentException("unsetType cannot be null when passed to InverseSingleBlockTypeMask");
    }
    return null;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) SingleBlockStateMask(com.fastasyncworldedit.core.function.mask.SingleBlockStateMask)

Aggregations

SingleBlockStateMask (com.fastasyncworldedit.core.function.mask.SingleBlockStateMask)1 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1