2021-10-08 10:00:03 +00: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
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2021-11-25 01:24:51 +00:00
|
|
|
index 27f03389f905e8e051eb4148016de7868c385819..b8e7f70f4ee1b28635537e04f7bd0d0cd6afb4b3 100644
|
2021-10-08 10:00:03 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2021-11-25 01:24:51 +00:00
|
|
|
@@ -748,6 +748,11 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-10-08 10:00:03 +00: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);
|
|
|
|
|
2021-11-25 01:24:51 +00:00
|
|
|
@@ -762,6 +767,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-10-08 10:00:03 +00: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
|
2021-11-25 08:54:06 +00:00
|
|
|
index 28516df29bfb3d51980e2ace74fa72bfc2151056..25ab3a26a46b592f0953047ecafed4733f037cd1 100644
|
2021-10-08 10:00:03 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2021-11-25 01:24:51 +00:00
|
|
|
@@ -690,6 +690,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2021-10-08 10:00:03 +00:00
|
|
|
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);
|