Fix BlockTransformExtent rotating directional boolean properties.

Also add support for redstone dust, which is directional non-boolean.
(It's the only block like this atm.)
This commit is contained in:
wizjany 2019-06-15 12:09:48 -04:00
parent 0088fe79b3
commit 0aa0dbfd11

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.extent.transform; package com.sk89q.worldedit.extent.transform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
@ -38,14 +36,16 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Locale;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Transforms blocks themselves (but not their position) according to a * Transforms blocks themselves (but not their position) according to a
@ -183,22 +183,35 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
} }
} }
List<String> directionalProperties = properties.stream() Map<String, Object> directionalProperties = new HashMap<>();
.filter(prop -> prop instanceof BooleanProperty) for (Property<?> prop : properties) {
.filter(prop -> directionNames.contains(prop.getName())) if (directionNames.contains(prop.getName())) {
.filter(property -> (Boolean) block.getState(property)) if (prop instanceof BooleanProperty && (Boolean) block.getState(prop)
.map(Property::getName) || prop instanceof EnumProperty && !block.getState(prop).toString().equals("none")) {
.map(String::toUpperCase) String origProp = prop.getName().toUpperCase(Locale.ROOT);
.map(Direction::valueOf) Direction dir = Direction.valueOf(origProp);
.map(dir -> Direction.findClosest(transform.apply(dir.toVector()), Direction.Flag.CARDINAL)) Direction closest = Direction.findClosest(transform.apply(dir.toVector()), Direction.Flag.CARDINAL);
.filter(Objects::nonNull) if (closest != null) {
.map(Direction::name) String closestProp = closest.name().toLowerCase(Locale.ROOT);
.map(String::toLowerCase) if (prop instanceof BooleanProperty) {
.collect(Collectors.toList()); result = result.with((BooleanProperty) prop, Boolean.FALSE);
directionalProperties.put(closestProp, Boolean.TRUE);
} else {
if (prop.getValues().contains("none")) {
//noinspection unchecked
result = result.with((Property<Object>) prop, "none");
}
directionalProperties.put(closestProp, block.getState(prop));
}
}
}
}
}
if (directionalProperties.size() > 0) { if (!directionalProperties.isEmpty()) {
for (String directionName : directionNames) { for (String directionName : directionNames) {
result = result.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName)); Property<Object> dirProp = block.getBlockType().getProperty(directionName);
result = result.with(dirProp, directionalProperties.get(directionName));
} }
} }