2021-06-11 12:02:28 +00: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 06:52:40 +00:00
|
|
|
index 5ce8ac377b0d2b05dd90baa67f420945cc419609..919a489a5c7b338659c62ae67fc0a6ceee9dcdf9 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2021-07-07 06:52:40 +00:00
|
|
|
@@ -975,11 +975,21 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-06-11 12:02:28 +00: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();
|
|
|
|
|
2021-06-12 15:06:20 +00:00
|
|
|
return !this.distanceManager.hasPlayersNearby(i) ? true : this.playerMap.getPlayers(i).noneMatch((entityplayer) -> {
|
|
|
|
+ // Paper start - add PlayerNaturallySpawnCreaturesEvent
|
2021-06-11 12:02:28 +00: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
|
2021-06-12 15:06:20 +00:00
|
|
|
return !entityplayer.isSpectator() && ChunkMap.euclideanDistanceSquared(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
|
2021-06-11 12:02:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2021-07-18 07:41:53 +00:00
|
|
|
index bafd97074461d5b17b21579ba493ba8eae8468d8..2c0dd4b5a751e413936f399106367d4b22c17dda 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2021-07-07 06:52:40 +00:00
|
|
|
@@ -631,6 +631,15 @@ public class ServerChunkCache extends ChunkSource {
|
2021-06-11 12:02:28 +00:00
|
|
|
this.level.getProfiler().pop();
|
|
|
|
//List<PlayerChunk> list = Lists.newArrayList(this.playerChunkMap.f()); // Paper
|
|
|
|
//Collections.shuffle(list); // Paper
|
|
|
|
+ //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
|
|
|
|
this.chunkMap.getChunks().forEach((playerchunk) -> { // Paper - no... just no...
|
|
|
|
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 06:52:40 +00:00
|
|
|
index 823fc38b5bbf5eac2d2e7cc48c4b0557d252f960..fb42d7e3a1a23c02e8fd2cc04e6986ead581018c 100644
|
2021-06-11 12:02:28 +00: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 06:52:40 +00:00
|
|
|
@@ -233,6 +234,7 @@ public class ServerPlayer extends Player {
|
2021-06-11 12:02:28 +00: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
|
|
|
|
|