|
127 | 127 | import com.sk89q.worldedit.regions.NullRegion; |
128 | 128 | import com.sk89q.worldedit.regions.Region; |
129 | 129 | import com.sk89q.worldedit.regions.RegionIntersection; |
| 130 | +import com.sk89q.worldedit.regions.RegionOperationException; |
130 | 131 | import com.sk89q.worldedit.regions.Regions; |
131 | 132 | import com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape; |
132 | 133 | import com.sk89q.worldedit.regions.shape.ArbitraryShape; |
@@ -1804,18 +1805,59 @@ public int stackCuboidRegion(Region region, BlockVector3 dir, int count, boolean |
1804 | 1805 | * @throws MaxChangedBlocksException thrown if too many blocks are changed |
1805 | 1806 | */ |
1806 | 1807 | public int stackCuboidRegion( |
1807 | | - Region region, BlockVector3 offset, int count, |
1808 | | - boolean copyEntities, boolean copyBiomes, Mask mask |
| 1808 | + Region region, |
| 1809 | + BlockVector3 offset, |
| 1810 | + int count, |
| 1811 | + boolean copyEntities, |
| 1812 | + boolean copyBiomes, |
| 1813 | + Mask mask |
1809 | 1814 | ) throws MaxChangedBlocksException { |
1810 | 1815 | checkNotNull(region); |
1811 | 1816 | checkNotNull(offset); |
| 1817 | + |
| 1818 | + BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); |
| 1819 | + try { |
| 1820 | + return stackRegionBlockUnits(region, offset.multiply(size), count, copyEntities, copyBiomes, mask); |
| 1821 | + } catch (RegionOperationException e) { |
| 1822 | + // Should never be able to happen |
| 1823 | + throw new AssertionError(e); |
| 1824 | + } |
| 1825 | + } |
| 1826 | + |
| 1827 | + /** |
| 1828 | + * Stack a region using block units. |
| 1829 | + * |
| 1830 | + * @param region the region to stack |
| 1831 | + * @param offset how far to move the contents each stack in block units |
| 1832 | + * @param count the number of times to stack |
| 1833 | + * @param copyEntities true to copy entities |
| 1834 | + * @param copyBiomes true to copy biomes |
| 1835 | + * @param mask source mask for the operation (only matching blocks are copied) |
| 1836 | + * @return number of blocks affected |
| 1837 | + * @throws MaxChangedBlocksException thrown if too many blocks are changed |
| 1838 | + * @throws RegionOperationException thrown if the region operation is invalid |
| 1839 | + */ |
| 1840 | + public int stackRegionBlockUnits( |
| 1841 | + Region region, |
| 1842 | + BlockVector3 offset, |
| 1843 | + int count, |
| 1844 | + boolean copyEntities, |
| 1845 | + boolean copyBiomes, |
| 1846 | + Mask mask |
| 1847 | + ) throws MaxChangedBlocksException, RegionOperationException { |
| 1848 | + checkNotNull(region); |
| 1849 | + checkNotNull(offset); |
1812 | 1850 | checkArgument(count >= 1, "count >= 1 required"); |
1813 | 1851 |
|
1814 | 1852 | BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); |
| 1853 | + BlockVector3 offsetAbs = offset.abs(); |
| 1854 | + if (offsetAbs.x() < size.x() && offsetAbs.y() < size.y() && offsetAbs.z() < size.z()) { |
| 1855 | + throw new RegionOperationException(Caption.of("worldedit.stack.intersecting-region")); |
| 1856 | + } |
1815 | 1857 | BlockVector3 to = region.getMinimumPoint(); |
1816 | 1858 | ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to); |
1817 | 1859 | copy.setRepetitions(count); |
1818 | | - copy.setTransform(new AffineTransform().translate(offset.multiply(size))); |
| 1860 | + copy.setTransform(new AffineTransform().translate(offset)); |
1819 | 1861 | copy.setCopyingEntities(copyEntities); |
1820 | 1862 | copy.setCopyingBiomes(copyBiomes); |
1821 | 1863 | final Region allowedRegion; |
|
0 commit comments