aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0035-Fast-draining.patch
blob: a025783717b5495930dce39fc8b29a992f223ddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
From d20531320914b578667604dc1a7d557b1c61b0f8 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Wed, 2 Mar 2016 12:20:52 -0600
Subject: [PATCH] Fast draining


diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index a7dfd2af7..e093f7dc1 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -185,4 +185,11 @@ public class PaperWorldConfig {
         optimizeExplosions = getBoolean("optimize-explosions", false);
         log("Optimize explosions: " + optimizeExplosions);
     }
+
+    public boolean fastDrainLava;
+    public boolean fastDrainWater;
+    private void fastDrain() {
+        fastDrainLava = getBoolean("fast-drain.lava", false);
+        fastDrainWater = getBoolean("fast-drain.water", false);
+    }
 }
diff --git a/src/main/java/net/minecraft/server/BlockFlowing.java b/src/main/java/net/minecraft/server/BlockFlowing.java
index 801b9cb7b..8e9de3bcb 100644
--- a/src/main/java/net/minecraft/server/BlockFlowing.java
+++ b/src/main/java/net/minecraft/server/BlockFlowing.java
@@ -69,7 +69,7 @@ public class BlockFlowing extends BlockFluids {
                 }
             }
 
-            if (this.material == Material.LAVA && i < 8 && i1 < 8 && i1 > i && random.nextInt(4) != 0) {
+            if (!world.paperConfig.fastDrainLava && this.material == Material.LAVA && i < 8 && i1 < 8 && i1 > i && random.nextInt(4) != 0) { // Paper
                 j *= 4;
             }
 
@@ -77,7 +77,7 @@ public class BlockFlowing extends BlockFluids {
                 this.f(world, blockposition, iblockdata);
             } else {
                 i = i1;
-                if (i1 < 0) {
+                if (i1 < 0 || canFastDrain(world, blockposition)) { // Paper - Fast draining
                     world.setAir(blockposition);
                 } else {
                     iblockdata = iblockdata.set(BlockFlowing.LEVEL, Integer.valueOf(i1));
@@ -267,6 +267,7 @@ public class BlockFlowing extends BlockFluids {
 
     }
 
+    // Paper start
     /**
      * Paper - Get flow speed. Throttle if its water and flowing adjacent to lava
      */
@@ -280,4 +281,57 @@ public class BlockFlowing extends BlockFluids {
         }
         return super.a(world);
     }
+
+    private int getFluidLevel(IBlockAccess iblockaccess, BlockPosition blockposition) {
+        return iblockaccess.getType(blockposition).getMaterial() == this.material ? iblockaccess.getType(blockposition).get(BlockFluids.LEVEL) : -1;
+    }
+
+    /**
+     * Paper - Data check method for fast draining
+     */
+    public int getData(World world, BlockPosition position) {
+        int data = this.getFluidLevel((IBlockAccess) world, position);
+        return data < 8 ? data : 0;
+    }
+
+    /**
+     * Paper - Checks surrounding blocks to determine if block can be fast drained
+     */
+    public boolean canFastDrain(World world, BlockPosition position) {
+        boolean result = false;
+        int data = getData(world, position);
+        if (this.material == Material.WATER) {
+            if (world.paperConfig.fastDrainWater) {
+                result = true;
+                if (getData(world, position.down()) < 0) {
+                    result = false;
+                } else if (world.getType(position.north()).getBlock().getBlockData().getMaterial() == Material.WATER && getData(world, position.north()) < data) {
+                    result = false;
+                } else if (world.getType(position.south()).getBlock().getBlockData().getMaterial() == Material.WATER && getData(world, position.south()) < data) {
+                    result = false;
+                } else if (world.getType(position.west()).getBlock().getBlockData().getMaterial() == Material.WATER && getData(world, position.west()) < data) {
+                    result = false;
+                } else if (world.getType(position.east()).getBlock().getBlockData().getMaterial() == Material.WATER && getData(world, position.east()) < data) {
+                    result = false;
+                }
+            }
+        } else if (this.material == Material.LAVA) {
+            if (world.paperConfig.fastDrainLava) {
+                result = true;
+                if (getData(world, position.down()) < 0 || world.getType(position.up()).getBlock().getBlockData().getMaterial() != Material.AIR) {
+                    result = false;
+                } else if (world.getType(position.north()).getBlock().getBlockData().getMaterial() == Material.LAVA && getData(world, position.north()) < data) {
+                    result = false;
+                } else if (world.getType(position.south()).getBlock().getBlockData().getMaterial() == Material.LAVA && getData(world, position.south()) < data) {
+                    result = false;
+                } else if (world.getType(position.west()).getBlock().getBlockData().getMaterial() == Material.LAVA && getData(world, position.west()) < data) {
+                    result = false;
+                } else if (world.getType(position.east()).getBlock().getBlockData().getMaterial() == Material.LAVA && getData(world, position.east()) < data) {
+                    result = false;
+                }
+            }
+        }
+        return result;
+    }
+    // Paper end
 }
-- 
2.12.0.windows.1