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
|
2023-03-14 19:59:51 +01:00
|
|
|
index 9246ce9f654ad4db6155b026778a83d4ee79624d..526ffddc27d85237dd2f8a1028945fa58ffaefb2 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
|
2023-03-14 19:59:51 +01:00
|
|
|
@@ -695,7 +695,9 @@ 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
|
2021-11-23 15:03:50 +01:00
|
|
|
+ double blockRange = 16384.0D; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
// Spigot end
|
|
|
|
long i = chunkcoordintpair.toLong();
|
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
@@ -712,6 +714,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-11-23 15:03:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
+ // Paper start - add PlayerNaturallySpawnCreaturesEvent
|
|
|
|
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
|
|
|
|
+ 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
|
|
|
|
} while (!this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair, blockRange)); // Spigot
|
|
|
|
|
|
|
|
return true;
|
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
|
2022-12-07 19:52:24 +01:00
|
|
|
index 80d108ae7faf3fdcb024931e93032215935fe70b..c021733342c09adb04ce3f675209543f84ac4bda 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
|
2022-12-07 19:52:24 +01:00
|
|
|
@@ -715,6 +715,15 @@ public class ServerChunkCache extends ChunkSource {
|
2021-11-23 15:03:50 +01:00
|
|
|
boolean flag2 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
|
2021-08-02 10:00:31 +02:00
|
|
|
|
2021-12-05 15:00:13 +01:00
|
|
|
Collections.shuffle(list);
|
2021-09-11 12:22:51 +02:00
|
|
|
+ // Paper start - call player naturally spawn event
|
2021-06-11 14:02:28 +02:00
|
|
|
+ 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
|
2021-11-23 15:03:50 +01:00
|
|
|
Iterator iterator1 = list.iterator();
|
|
|
|
|
|
|
|
while (iterator1.hasNext()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2023-03-26 22:29:41 +02:00
|
|
|
index 9d04d3d1e24222bf255a1fc96761909574f67d66..67b0a9f8e8f122c406057c5db225fa6a03dd624c 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;
|
2023-03-14 19:59:51 +01:00
|
|
|
import com.google.common.net.InetAddresses;
|
2021-06-11 14:02:28 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2023-03-26 22:29:41 +02:00
|
|
|
@@ -258,6 +259,7 @@ public class ServerPlayer extends Player {
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit end
|
2022-09-26 10:02:51 +02:00
|
|
|
public boolean isRealPlayer; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
|
2022-12-07 19:52:24 +01:00
|
|
|
+ public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
|
|
|
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
|
|
|
|
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
|