Permalink
Browse files

Properly rotate fences etc

  • Loading branch information...
me4502 committed Oct 8, 2018
1 parent 88f22f2 commit 6ecbf19406b5ae72022ea4a0280f4f22eabeea53
@@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
@@ -33,6 +34,11 @@
import com.sk89q.worldedit.world.block.BlockState;
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;
/**
@@ -105,6 +111,8 @@ public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEdi
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.
*
@@ -117,7 +125,9 @@ public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEdi
checkNotNull(block);
checkNotNull(transform);
for (Property property : block.getBlockType().getProperties()) {
List<? extends Property> properties = block.getBlockType().getProperties();
for (Property property : properties) {
if (property instanceof DirectionalProperty) {
Direction value = (Direction) block.getState(property);
if (value != null) {
@@ -129,6 +139,24 @@ public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEdi
}
}
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;
}
@@ -9,7 +9,7 @@ buildscript {
plugins {
id 'signing'
id 'org.spongepowered.plugin' version '0.8.1'
id 'org.spongepowered.plugin' version '0.9.0'
}
repositories {

0 comments on commit 6ecbf19

Please sign in to comment.