From 6ecbf19406b5ae72022ea4a0280f4f22eabeea53 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 8 Oct 2018 22:32:07 +1000 Subject: [PATCH] Properly rotate fences etc --- .../transform/BlockTransformExtent.java | 30 ++++++++++++++++++- worldedit-sponge/build.gradle | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 7b44ce4b5..8fea3cb81 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.extent.transform; 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.util.Direction; 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 class BlockTransformExtent extends AbstractDelegateExtent { return transform(block, transform, block); } + private static final Set directionNames = Sets.newHashSet("north", "south", "east", "west"); + /** * Transform the given block using the given transform. * @@ -117,7 +125,9 @@ public class BlockTransformExtent extends AbstractDelegateExtent { checkNotNull(block); checkNotNull(transform); - for (Property property : block.getBlockType().getProperties()) { + List 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 class BlockTransformExtent extends AbstractDelegateExtent { } } + List 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; } diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index ec3da06c1..4aac1db72 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -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 {