Search in sources :

Example 1 with DirectionProperty

use of net.minecraft.state.property.DirectionProperty in project FastAsyncWorldEdit by IntellectualSites.

the class FabricAdapter method applyProperties.

private static net.minecraft.block.BlockState applyProperties(StateFactory<Block, net.minecraft.block.BlockState> stateContainer, net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
    for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
        net.minecraft.state.property.Property property = stateContainer.getProperty(state.getKey().getName());
        Comparable value = (Comparable) state.getValue();
        // we may need to adapt this value, depending on the source prop
        if (property instanceof DirectionProperty) {
            Direction dir = (Direction) value;
            value = adapt(dir);
        } else if (property instanceof net.minecraft.state.property.EnumProperty) {
            String enumName = (String) value;
            value = ((net.minecraft.state.property.EnumProperty<?>) property).getValue((String) value).orElseGet(() -> {
                throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
            });
        }
        newState = newState.with(property, value);
    }
    return newState;
}
Also used : Direction(com.sk89q.worldedit.util.Direction) DirectionProperty(net.minecraft.state.property.DirectionProperty) Map(java.util.Map) TreeMap(java.util.TreeMap) Property(com.sk89q.worldedit.registry.state.Property) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty) BooleanProperty(com.sk89q.worldedit.registry.state.BooleanProperty) DirectionProperty(net.minecraft.state.property.DirectionProperty) EnumProperty(com.sk89q.worldedit.registry.state.EnumProperty) IntegerProperty(com.sk89q.worldedit.registry.state.IntegerProperty)

Aggregations

BooleanProperty (com.sk89q.worldedit.registry.state.BooleanProperty)1 DirectionalProperty (com.sk89q.worldedit.registry.state.DirectionalProperty)1 EnumProperty (com.sk89q.worldedit.registry.state.EnumProperty)1 IntegerProperty (com.sk89q.worldedit.registry.state.IntegerProperty)1 Property (com.sk89q.worldedit.registry.state.Property)1 Direction (com.sk89q.worldedit.util.Direction)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 DirectionProperty (net.minecraft.state.property.DirectionProperty)1