Properly rotate fences etc

This commit is contained in:
Matthew Miller 2018-10-08 22:32:07 +10:00
parent 88f22f2e59
commit 6ecbf19406
2 changed files with 30 additions and 2 deletions

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extent.transform;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
@ -33,6 +34,11 @@ import com.sk89q.worldedit.util.Direction;
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 java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -105,6 +111,8 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
return transform(block, transform, block); return transform(block, transform, block);
} }
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
/** /**
* Transform the given block using the given transform. * Transform the given block using the given transform.
* *
@ -117,7 +125,9 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
checkNotNull(block); checkNotNull(block);
checkNotNull(transform); checkNotNull(transform);
for (Property property : block.getBlockType().getProperties()) { List<? extends Property> properties = block.getBlockType().getProperties();
for (Property property : properties) {
if (property instanceof DirectionalProperty) { if (property instanceof DirectionalProperty) {
Direction value = (Direction) block.getState(property); Direction value = (Direction) block.getState(property);
if (value != null) { if (value != null) {
@ -129,6 +139,24 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
} }
} }
List<String> directionalProperties = properties.stream()
.filter(prop -> directionNames.contains(prop.getName()))
.filter(prop -> ((Boolean) block.getState(prop)))
.map(Property::getName)
.map(String::toUpperCase)
.map(Direction::valueOf)
.map(dir -> Direction.findClosest(transform.apply(dir.toVector()), Direction.Flag.CARDINAL))
.filter(Objects::nonNull)
.map(Direction::name)
.map(String::toLowerCase)
.collect(Collectors.toList());
if (directionalProperties.size() > 0) {
for (String directionName : directionNames) {
changedBlock = (T) changedBlock.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName));
}
}
return changedBlock; return changedBlock;
} }

View File

@ -9,7 +9,7 @@ buildscript {
plugins { plugins {
id 'signing' id 'signing'
id 'org.spongepowered.plugin' version '0.8.1' id 'org.spongepowered.plugin' version '0.9.0'
} }
repositories { repositories {