Paper/patches/server/0173-PlayerNaturallySpawnCreaturesEvent.patch

77 Zeilen
4.6 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
2021-07-07 08:52:40 +02:00
index 5ce8ac377b0d2b05dd90baa67f420945cc419609..919a489a5c7b338659c62ae67fc0a6ceee9dcdf9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
2021-07-07 08:52:40 +02:00
@@ -975,11 +975,21 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
chunkRange = (chunkRange > level.spigotConfig.viewDistance) ? (byte) level.spigotConfig.viewDistance : chunkRange;
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
+ final int finalChunkRange = chunkRange; // Paper for lambda below
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
// Spigot end
long i = chunkcoordintpair.toLong();
return !this.distanceManager.hasPlayersNearby(i) ? true : this.playerMap.getPlayers(i).noneMatch((entityplayer) -> {
+ // Paper start - add PlayerNaturallySpawnCreaturesEvent
2021-06-11 14:02:28 +02:00
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
+ double blockRange = 16384.0D;
+ if (reducedRange) {
+ event = entityplayer.playerNaturallySpawnedEvent;
+ if (event == null || event.isCancelled()) return false;
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
+ }
+ // Paper end
return !entityplayer.isSpectator() && ChunkMap.euclideanDistanceSquared(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
2021-06-11 14:02:28 +02:00
});
}
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index c5bffd1b40ca9ae3c973044c1ad4947ba2c285ae..918555ba0af8a779ad55c7cf73f615eb804d00d9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -632,6 +632,15 @@ public class ServerChunkCache extends ChunkSource {
List<ChunkHolder> list = Lists.newArrayList(this.chunkMap.getChunks());
Collections.shuffle(list);
2021-06-11 14:02:28 +02:00
+ //Paper start - call player naturally spawn event
+ int chunkRange = level.spigotConfig.mobSpawnRange;
+ chunkRange = (chunkRange > level.spigotConfig.viewDistance) ? (byte) level.spigotConfig.viewDistance : chunkRange;
+ chunkRange = Math.min(chunkRange, 8);
+ for (ServerPlayer entityPlayer : this.level.players()) {
+ entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
+ entityPlayer.playerNaturallySpawnedEvent.callEvent();
+ };
+ // Paper end
this.level.timings.chunkTicks.startTiming(); // Paper
list.forEach((playerchunk) -> {
2021-06-11 14:02:28 +02:00
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2021-07-07 08:52:40 +02:00
index 823fc38b5bbf5eac2d2e7cc48c4b0557d252f960..fb42d7e3a1a23c02e8fd2cc04e6986ead581018c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1,5 +1,6 @@
package net.minecraft.server.level;
+import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Either;
2021-07-07 08:52:40 +02:00
@@ -233,6 +234,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
public boolean sentListPacket = false;
public Integer clientViewDistance;
// CraftBukkit end
+ public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper