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
This commit is contained in:
Brokkonaut
2019-11-12 12:09:28 +01:00
committed by Matthew Miller
parent 23a3929051
commit 89bc664f69
2 changed files with 41 additions and 0 deletions

View File

@ -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;