2021-10-08 12:00:03 +02:00
|
|
|
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
|
|
|
|
|
2022-11-20 00:53:20 +01:00
|
|
|
== AT ==
|
|
|
|
public net.minecraft.server.level.ServerLevel findLightningRod(Lnet/minecraft/core/BlockPos;)Ljava/util/Optional;
|
2021-10-08 12:00:03 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-09-22 22:13:57 +02:00
|
|
|
index b71e404acd353757cb64489cfe3804988db70409..257eedb5413521e1e3ce6a6a6376e0c8175c8c5e 100644
|
2021-10-08 12:00:03 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -976,6 +976,11 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-10-08 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -990,6 +995,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-10-08 12:00:03 +02:00
|
|
|
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
|
2023-09-23 04:06:03 +02:00
|
|
|
index 975b7c20f3755e463c1d65d8de7d63f26bfaf56b..e4eb19d37ec3128a0f0c96e154605fccc8ba822a 100644
|
2021-10-08 12:00:03 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -693,6 +693,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-10-08 12:00:03 +02:00
|
|
|
return (LightningStrike) lightning.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public Location findLightningRod(Location location) {
|
2022-10-24 21:43:46 +02:00
|
|
|
+ return this.world.findLightningRod(io.papermc.paper.util.MCUtil.toBlockPosition(location))
|
|
|
|
+ .map(blockPos -> io.papermc.paper.util.MCUtil.toLocation(this.world, blockPos)
|
2021-10-08 12:00:03 +02:00
|
|
|
+ // get the actual rod pos
|
|
|
|
+ .subtract(0, 1, 0))
|
|
|
|
+ .orElse(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Location findLightningTarget(Location location) {
|
2022-10-24 21:43:46 +02:00
|
|
|
+ final BlockPos pos = this.world.findLightningTargetAround(io.papermc.paper.util.MCUtil.toBlockPosition(location), true);
|
|
|
|
+ return pos == null ? null : io.papermc.paper.util.MCUtil.toLocation(this.world, pos);
|
2021-10-08 12:00:03 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public boolean generateTree(Location loc, TreeType type) {
|
|
|
|
return generateTree(loc, CraftWorld.rand, type);
|