From 89bc664f69da9fcfe9b225d805d5684f2dfab37f Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 12 Nov 2019 12:09:28 +0100 Subject: [PATCH] Fix flipping of chests and stairs (#526) * Fix flipping of chests and stairs * Check if the new property value is valid before updating * Only for horizontal flips double chests/stairs should be modified --- .../transform/BlockTransformExtent.java | 33 +++++++++++++++++++ .../math/transform/AffineTransform.java | 8 +++++ 2 files changed, 41 insertions(+) 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 fe577e709..46081ab94 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 @@ -25,6 +25,7 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty; @@ -162,6 +163,38 @@ public class BlockTransformExtent extends AbstractDelegateExtent { } } } + } else if (property.getName().equals("type") && transform instanceof AffineTransform) { + // chests + if (((AffineTransform) transform).isHorizontalFlip()) { + String value = (String) block.getState(property); + String newValue = null; + if ("left".equals(value)) { + newValue = "right"; + } else if ("right".equals(value)) { + newValue = "left"; + } + if (newValue != null && enumProp.getValues().contains(newValue)) { + result = result.with(enumProp, newValue); + } + } + } else if (property.getName().equals("shape") && transform instanceof AffineTransform) { + // stairs + if (((AffineTransform) transform).isHorizontalFlip()) { + String value = (String) block.getState(property); + String newValue = null; + if ("outer_left".equals(value)) { + newValue = "outer_right"; + } else if ("outer_right".equals(value)) { + newValue = "outer_left"; + } else if ("inner_left".equals(value)) { + newValue = "inner_right"; + } else if ("inner_right".equals(value)) { + newValue = "inner_left"; + } + if (newValue != null && enumProp.getValues().contains(newValue)) { + result = result.with(enumProp, newValue); + } + } } } else if (property instanceof IntegerProperty) { IntegerProperty intProp = (IntegerProperty) property; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java index f3e9a3876..6cb976440 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java @@ -312,6 +312,14 @@ public class AffineTransform implements Transform { } } + /** + * Returns if this affine transform is representing a horizontal flip. + */ + public boolean isHorizontalFlip() { + // use the determinant of the x-z submatrix to check if this is a horizontal flip + return m00 * m22 - m02 * m20 < 0; + } + @Override public String toString() { return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);