SteamWar/FightSystem
Archiviert
13
1

Waterremover improvements #225

Manuell gemergt
Lixfel hat 1 Commits von improveWaterremover nach master 2021-01-02 13:16:39 +01:00 zusammengeführt
Nur Änderungen aus Commit 1112b86742 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.fightsystem.utils;
import de.steamwar.core.Core;
import org.bukkit.Material;
import de.steamwar.fightsystem.Config;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -29,48 +29,33 @@ import java.util.List;
public class WaterRemover {
private WaterRemover(){}
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
public static void add(List<Block> l) {
for(Block b : l){
//b cannot be water or air due to current explosion
int startX = b.getX();
int startY = b.getY();
int startZ = b.getZ();
try{
checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
}catch(IsAnOcean e){
//ignore
}
checkBlock(b.getRelative(BlockFace.UP));
checkBlock(b.getRelative(BlockFace.EAST));
checkBlock(b.getRelative(BlockFace.WEST));
checkBlock(b.getRelative(BlockFace.NORTH));
checkBlock(b.getRelative(BlockFace.SOUTH));
}
}
private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean {
private static void checkBlock(Block b) {
if(!removeWater(b))
return;
// If distance to original block is greater than 20
if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20){
b.setType(Material.WATER);
throw new IsAnOcean();
}
if(b.getY() < MIN_Y)
return;
try{
checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
}catch(IsAnOcean e){
b.setType(Material.WATER);
throw e;
checkBlock(b.getRelative(BlockFace.UP));
checkBlock(b.getRelative(BlockFace.EAST));
checkBlock(b.getRelative(BlockFace.WEST));
checkBlock(b.getRelative(BlockFace.NORTH));
checkBlock(b.getRelative(BlockFace.SOUTH));
}
}
private static class IsAnOcean extends Throwable{}
public static boolean isWater(Block block){
switch(Core.getVersion()){