Added a few new things using block states.

* `//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).
This commit is contained in:
wizjany
2019-02-12 16:39:09 -05:00
parent 1ae0e88b63
commit 88014b18a3
19 changed files with 711 additions and 49 deletions

View File

@ -19,9 +19,13 @@
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.
@ -48,4 +52,28 @@ public final class Blocks {
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;
}
}