2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
|
|
|
|
2020-02-29 23:39:00 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-06-25 13:11:48 +00:00
|
|
|
index 7abd3683f9cc21b90dc74739954de2decddf6478..6921def2dc8dd7f2b8ba9d46ab697a9f9b62cf4e 100644
|
2020-02-29 23:39:00 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-06-25 13:11:48 +00:00
|
|
|
@@ -589,6 +589,15 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-02-29 23:39:00 +00:00
|
|
|
this.world.getMethodProfiler().exit();
|
2020-06-25 13:11:48 +00:00
|
|
|
//List<PlayerChunk> list = Lists.newArrayList(this.playerChunkMap.f()); // Paper
|
|
|
|
//Collections.shuffle(list); // Paper
|
2020-02-29 23:39:00 +00:00
|
|
|
+ //Paper start - call player naturally spawn event
|
|
|
|
+ int chunkRange = world.spigotConfig.mobSpawnRange;
|
|
|
|
+ chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
|
|
|
|
+ chunkRange = Math.min(chunkRange, 8);
|
2020-06-25 13:11:48 +00:00
|
|
|
+ for (EntityPlayer entityPlayer : this.world.getPlayers()) {
|
2020-02-29 23:39:00 +00:00
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
|
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent.callEvent();
|
|
|
|
+ };
|
|
|
|
+ // Paper end
|
2020-06-25 13:11:48 +00:00
|
|
|
this.playerChunkMap.f().forEach((playerchunk) -> { // Paper - no... just no...
|
|
|
|
Optional<Chunk> optional = ((Either) playerchunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left();
|
2020-02-29 23:39:00 +00:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2020-07-22 23:35:44 +00:00
|
|
|
index b94afac539a5d7a1e6ed39ef8f130385f8ea07b6..ef0f8a66eefefce5f78ff35833bfe45437885e0b 100644
|
2020-02-29 23:39:00 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
+import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.datafixers.util.Either;
|
2020-06-25 13:11:48 +00:00
|
|
|
@@ -93,6 +94,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2020-02-29 23:39:00 +00:00
|
|
|
public boolean sentListPacket = false;
|
|
|
|
public Integer clientViewDistance;
|
|
|
|
// CraftBukkit end
|
|
|
|
+ public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
|
|
|
|
|
|
|
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<EntityPlayer> cachedSingleHashSet; // Paper
|
|
|
|
|
2019-04-28 17:59:47 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2020-06-26 01:58:00 +00:00
|
|
|
index 465beba397f05a31dcda9840375a0e9b97153e78..4ae3e91677ecf9c2104a229b4e8b229d18b87aa4 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-06-25 13:11:48 +00:00
|
|
|
@@ -912,12 +912,23 @@ 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) {
|
2020-02-29 23:39:00 +00:00
|
|
|
+ event = entityplayer.playerNaturallySpawnedEvent;
|
|
|
|
+ if (event == null || event.isCancelled()) return false;
|
2019-06-06 05:13:00 +00:00
|
|
|
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|