|
54 | 54 | import com.sk89q.worldedit.function.block.Counter; |
55 | 55 | import com.sk89q.worldedit.function.block.Naturalizer; |
56 | 56 | import com.sk89q.worldedit.function.block.SnowSimulator; |
| 57 | +import com.sk89q.worldedit.function.block.Thawer; |
57 | 58 | import com.sk89q.worldedit.function.generator.ForestGenerator; |
58 | 59 | import com.sk89q.worldedit.function.generator.GardenPatchGenerator; |
59 | 60 | import com.sk89q.worldedit.function.mask.BlockMask; |
@@ -2075,49 +2076,24 @@ public final int thaw(BlockVector3 position, double radius) |
2075 | 2076 | */ |
2076 | 2077 | public int thaw(BlockVector3 position, double radius, int height) |
2077 | 2078 | throws MaxChangedBlocksException { |
2078 | | - int affected = 0; |
2079 | | - double radiusSq = radius * radius; |
2080 | | - |
2081 | | - int ox = position.x(); |
2082 | | - int oy = position.y(); |
2083 | | - int oz = position.z(); |
2084 | | - |
2085 | | - BlockState air = BlockTypes.AIR.getDefaultState(); |
2086 | | - BlockState water = BlockTypes.WATER.getDefaultState(); |
2087 | | - |
2088 | | - int centerY = Math.max(getWorld().getMinY(), Math.min(getWorld().getMaxY(), oy)); |
2089 | | - int minY = Math.max(getWorld().getMinY(), centerY - height); |
2090 | | - int maxY = Math.min(getWorld().getMaxY(), centerY + height); |
2091 | | - |
2092 | | - int ceilRadius = (int) Math.ceil(radius); |
2093 | | - for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { |
2094 | | - for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { |
2095 | | - if (BlockVector3.at(x, oy, z).distanceSq(position) > radiusSq) { |
2096 | | - continue; |
2097 | | - } |
2098 | | - |
2099 | | - for (int y = maxY; y > minY; --y) { |
2100 | | - BlockVector3 pt = BlockVector3.at(x, y, z); |
2101 | | - BlockType id = getBlock(pt).getBlockType(); |
2102 | 2079 |
|
2103 | | - if (id == BlockTypes.ICE) { |
2104 | | - if (setBlock(pt, water)) { |
2105 | | - ++affected; |
2106 | | - } |
2107 | | - } else if (id == BlockTypes.SNOW) { |
2108 | | - if (setBlock(pt, air)) { |
2109 | | - ++affected; |
2110 | | - } |
2111 | | - } else if (id.getMaterial().isAir()) { |
2112 | | - continue; |
2113 | | - } |
| 2080 | + return thaw(new CylinderRegion(position, Vector2.at(radius, radius), position.y() - height, position.y() + height)); |
| 2081 | + } |
2114 | 2082 |
|
2115 | | - break; |
2116 | | - } |
2117 | | - } |
2118 | | - } |
| 2083 | + /** |
| 2084 | + * Thaw blocks in a cylinder. |
| 2085 | + * |
| 2086 | + * @param region the region to thaw in |
| 2087 | + * @return number of blocks affected |
| 2088 | + * @throws MaxChangedBlocksException thrown if too many blocks are changed |
| 2089 | + */ |
| 2090 | + public final int thaw(FlatRegion region) throws MaxChangedBlocksException { |
| 2091 | + checkNotNull(region); |
2119 | 2092 |
|
2120 | | - return affected; |
| 2093 | + Thawer thawer = new Thawer(this); |
| 2094 | + LayerVisitor layerVisitor = new LayerVisitor(region, region.getMinimumY(), region.getMaximumY(), thawer); |
| 2095 | + Operations.completeLegacy(layerVisitor); |
| 2096 | + return thawer.getAffected(); |
2121 | 2097 | } |
2122 | 2098 |
|
2123 | 2099 | /** |
@@ -2151,7 +2127,7 @@ public final int simulateSnow(BlockVector3 position, double radius) throws MaxCh |
2151 | 2127 | public int simulateSnow(BlockVector3 position, double radius, int height) |
2152 | 2128 | throws MaxChangedBlocksException { |
2153 | 2129 |
|
2154 | | - return simulateSnow(new CylinderRegion(position, Vector2.at(radius, radius), position.y(), height), false); |
| 2130 | + return simulateSnow(new CylinderRegion(position, Vector2.at(radius, radius), position.y() - height, position.y() + height), false); |
2155 | 2131 | } |
2156 | 2132 |
|
2157 | 2133 |
|
|
0 commit comments