2020-02-09 19:32:40 +00:00
|
|
|
From a512d032fc82465e76cf0b6f8e67bd5c6fb051ad Mon Sep 17 00:00:00 2001
|
2019-04-28 17:59:47 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 14 Jan 2018 17:36:02 -0500
|
|
|
|
Subject: [PATCH] PlayerNaturallySpawnCreaturesEvent
|
|
|
|
|
|
|
|
This event can be used for when you want to exclude a certain player
|
|
|
|
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
|
2020-02-09 19:32:40 +00:00
|
|
|
index 936fc4f6b..b5da88587 100644
|
2019-04-28 17:59:47 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2020-01-28 00:16:53 +00:00
|
|
|
@@ -881,12 +881,24 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
2019-04-28 17:59:47 +00:00
|
|
|
chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
|
|
|
|
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
|
2019-05-30 23:54:25 +00:00
|
|
|
|
|
|
|
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
|
2019-04-28 17:59:47 +00:00
|
|
|
+ final int finalChunkRange = chunkRange; // Paper for lambda below
|
2019-05-30 23:54:25 +00:00
|
|
|
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
|
2019-04-28 17:59:47 +00:00
|
|
|
// Spigot end
|
2019-06-25 01:47:58 +00:00
|
|
|
long i = chunkcoordintpair.pair();
|
2019-04-28 17:59:47 +00:00
|
|
|
|
2019-07-20 04:01:24 +00:00
|
|
|
return !this.chunkDistanceManager.d(i) ? true : this.playerMap.a(i).noneMatch((entityplayer) -> {
|
2019-05-12 22:34:42 +00:00
|
|
|
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
|
2019-04-28 17:59:47 +00:00
|
|
|
+ // Paper start -
|
2019-06-06 05:13:00 +00:00
|
|
|
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
|
|
|
|
+ double blockRange = 16384.0D;
|
|
|
|
+ if (reducedRange) {
|
|
|
|
+ event = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityplayer.getBukkitEntity(), (byte) finalChunkRange);
|
2019-06-11 01:45:46 +00:00
|
|
|
+ event.callEvent();
|
2019-06-06 05:13:00 +00:00
|
|
|
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
|
2020-02-09 19:32:40 +00:00
|
|
|
+ if (event.isCancelled()) return false;
|
2019-06-06 05:13:00 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot
|
2019-04-28 17:59:47 +00:00
|
|
|
+ // Paper end
|
|
|
|
});
|
|
|
|
}
|
2019-05-12 22:34:42 +00:00
|
|
|
|
2019-04-28 17:59:47 +00:00
|
|
|
--
|
2020-02-09 19:32:40 +00:00
|
|
|
2.25.0
|
2019-04-28 17:59:47 +00:00
|
|
|
|