Sponge simulation now also clears waterlogged blocks.

Fixes WORLDGUARD-4011.
This commit is contained in:
wizjany 2019-02-15 16:00:30 -05:00
parent f9339e144e
commit a233be1df8

View File

@ -19,16 +19,23 @@
package com.sk89q.worldguard.util;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.config.WorldConfiguration;
import java.util.Map;
public final class SpongeUtil {
private static Map<BlockType, Property<Object>> waterloggable = Maps.newHashMap();
private SpongeUtil() {
}
@ -41,7 +48,7 @@ private static boolean isReplacable(BlockType blockType) {
/**
* Remove water around a sponge.
*
* @param world The world the sponge isin
* @param world The world the sponge is in
* @param ox The x coordinate of the 'sponge' block
* @param oy The y coordinate of the 'sponge' block
* @param oz The z coordinate of the 'sponge' block
@ -53,12 +60,25 @@ public static void clearSpongeWater(World world, int ox, int oy, int oz) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
BlockState block = world.getBlock(vector);
BlockType blockType = block.getBlockType();
if (isReplacable(blockType)) {
try {
world.setBlock(vector, BlockTypes.AIR.getDefaultState());
} catch (WorldEditException e) {
e.printStackTrace();
}
} else {
@SuppressWarnings("unchecked")
Property<Object> waterloggedProp = waterloggable.computeIfAbsent(blockType,
(bt -> (Property<Object>) bt.getPropertyMap().get("waterlogged")));
if (waterloggedProp != null) {
try {
world.setBlock(vector, block.with(waterloggedProp, false));
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
}