mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-07-08 18:00:04 +00:00
* `//set ##*tag` sets all states in the tag (not just default state per type) * `//set ^type` is a pattern changing block type but copying all valid existing states * `//set ^[prop=val,...]` sets the property `prop` to `val` wherever the existing block has that property * `//set ^type[prop=val,...]` does both of the above Those work anywhere a pattern is taken, of course. * The mask syntax `^[prop=val]` matches blocks with the property `prop` set to `val`, or blocks that don't have the property at all. * The mask syntax `^=[prop=val]` only matches blocks that have the property. Those work anywhere a mask is taken, of course. (`//mask`, `//gmask`, `//replace`, etc) The `//drain` command now takes `-w` flag that removes the waterlogged state from blocks (in addition to removing water, as before).
80 lines
2.8 KiB
Java
80 lines
2.8 KiB
Java
/*
|
|
* 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 Lesser 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 Lesser General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.sk89q.worldedit.blocks;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import com.sk89q.worldedit.registry.state.Property;
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
|
import com.sk89q.worldedit.world.block.BlockType;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Block-related utility methods.
|
|
*/
|
|
public final class Blocks {
|
|
|
|
private Blocks() {
|
|
}
|
|
|
|
/**
|
|
* Checks whether a given block is in a list of base blocks.
|
|
*
|
|
* @param collection the collection
|
|
* @param o the block
|
|
* @return true if the collection contains the given block
|
|
*/
|
|
public static <B extends BlockStateHolder<B>> boolean containsFuzzy(Collection<? extends BlockStateHolder<?>> collection, B o) {
|
|
// Allow masked data in the searchBlocks to match various types
|
|
for (BlockStateHolder<?> b : collection) {
|
|
if (b.equalsFuzzy(o)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Parses a string->string map to find the matching Property and values for the given BlockType.
|
|
*
|
|
* @param states the desired states and values
|
|
* @param type the block type to get properties and values for
|
|
* @return a property->value map
|
|
*/
|
|
public static Map<Property<Object>, Object> resolveProperties(Map<String, String> states, BlockType type) {
|
|
Map<String, ? extends Property<?>> existing = type.getPropertyMap();
|
|
Map<Property<Object>, Object> newMap = Maps.newHashMap();
|
|
states.forEach((key, value) -> {
|
|
@SuppressWarnings("unchecked")
|
|
Property<Object> prop = (Property<Object>) existing.get(key);
|
|
if (prop == null) return;
|
|
Object val = null;
|
|
try {
|
|
val = prop.getValueFor(value);
|
|
} catch (IllegalArgumentException ignored) {
|
|
}
|
|
if (val == null) return;
|
|
newMap.put(prop, val);
|
|
});
|
|
return newMap;
|
|
}
|
|
}
|