Resolve TODO on PlayerNaturallySpawnCreaturesEvent

- Add missing isCancelled check

We don't need to worry about going out of range of int
since the value is clamped to view distance, and view
distance is clamped to 33
This commit is contained in:
Spottedleaf 2019-05-12 15:34:42 -07:00 committed by Zach
parent 92e77aa7cb
commit 5a44b38dc5

View File

@ -1,4 +1,4 @@
From e1761ca14d86a46faf103fcf2d34fd79e208a14a Mon Sep 17 00:00:00 2001
From 19b85fdd78fce59a1e4c21342c6941a6c36df28c Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 14 Jan 2018 17:36:02 -0500
Subject: [PATCH] PlayerNaturallySpawnCreaturesEvent
@ -9,10 +9,10 @@ from triggering monster spawns on a server.
Also a highly more effecient way to blanket block spawns in a world
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 8e40027acf..eee03e39b1 100644
index 8e40027ac..e44570c60 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -675,11 +675,16 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -675,12 +675,17 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
int chunkRange = world.spigotConfig.mobSpawnRange;
chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
@ -23,14 +23,16 @@ index 8e40027acf..eee03e39b1 100644
// Spigot end
return this.y.a(chunkcoordintpair.pair()).noneMatch((entityplayer) -> {
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
+ // Paper start -
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event // TODO deal with int->byte on review (as well as the mess that this code is)
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event
+ = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityplayer.getBukkitEntity(), (byte)finalChunkRange);
+ final double blockRange = (double)((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
+ return event.isCancelled() || (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot
+ // Paper end
return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
});
}
--
2.21.0