aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0708-Add-methods-to-find-targets-for-lightning-strikes.patch
blob: 6880c6cd6839fe48cab52eb5667b2675663eb3ca (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jakub Zacek <dawon@dawon.eu>
Date: Mon, 4 Oct 2021 10:16:44 +0200
Subject: [PATCH] Add methods to find targets for lightning strikes


diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index d0c4c9c172c8caa3eaf6c0bf56a8be9f16d8c4e7..10421fdac40c756c52abc9430f7149a9f58efbfb 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -780,6 +780,11 @@ public class ServerLevel extends Level implements WorldGenLevel {
     }
 
     protected BlockPos findLightningTargetAround(BlockPos pos) {
+        // Paper start
+        return this.findLightningTargetAround(pos, false);
+    }
+    public BlockPos findLightningTargetAround(BlockPos pos, boolean returnNullWhenNoTarget) {
+        // Paper end
         BlockPos blockposition1 = this.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos);
         Optional<BlockPos> optional = this.findLightningRod(blockposition1);
 
@@ -794,6 +799,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
             if (!list.isEmpty()) {
                 return ((LivingEntity) list.get(this.random.nextInt(list.size()))).blockPosition();
             } else {
+                if (returnNullWhenNoTarget) return null; // Paper
                 if (blockposition1.getY() == this.getMinBuildHeight() - 1) {
                     blockposition1 = blockposition1.above(2);
                 }
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 2bed5b4eaeac4e48df606b755489a3ca5ffc895e..38a74d683aec58a419af84111844a205596524b2 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -696,6 +696,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
         return (LightningStrike) lightning.getBukkitEntity();
     }
 
+    // Paper start
+    @Override
+    public Location findLightningRod(Location location) {
+        return this.world.findLightningRod(net.minecraft.server.MCUtil.toBlockPosition(location))
+            .map(blockPos -> net.minecraft.server.MCUtil.toLocation(this.world, blockPos)
+                // get the actual rod pos
+                .subtract(0, 1, 0))
+            .orElse(null);
+    }
+
+    @Override
+    public Location findLightningTarget(Location location) {
+        final BlockPos pos = this.world.findLightningTargetAround(net.minecraft.server.MCUtil.toBlockPosition(location), true);
+        return pos == null ? null : net.minecraft.server.MCUtil.toLocation(this.world, pos);
+    }
+    // Paper end
+
     @Override
     public boolean generateTree(Location loc, TreeType type) {
         return generateTree(loc, CraftWorld.rand, type);