2020-05-06 15:44:47 +08:00
|
|
|
From ca9958e43d57e7f1c3d78791a939fe61a3e1ac71 Mon Sep 17 00:00:00 2001
|
2019-04-29 01:59:47 +08: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-03-01 07:39:00 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-05-02 06:03:47 +08:00
|
|
|
index fa4ad0b6dc..8c6550433c 100644
|
2020-03-01 07:39:00 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-04-24 17:33:33 +08:00
|
|
|
@@ -589,6 +589,15 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-03-01 07:39:00 +08:00
|
|
|
|
|
|
|
this.world.timings.countNaturalMobs.stopTiming(); // Paper - timings
|
|
|
|
this.world.getMethodProfiler().exit();
|
|
|
|
+ //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);
|
|
|
|
+ for (EntityPlayer entityPlayer : this.world.players) {
|
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
|
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent.callEvent();
|
|
|
|
+ };
|
|
|
|
+ // Paper end
|
|
|
|
this.playerChunkMap.f().forEach((playerchunk) -> {
|
|
|
|
Optional<Chunk> optional = ((Either) playerchunk.b().getNow(PlayerChunk.UNLOADED_CHUNK)).left();
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2020-05-02 06:03:47 +08:00
|
|
|
index bf32997c42..88692d9eae 100644
|
2020-03-01 07:39:00 +08: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;
|
|
|
|
@@ -89,6 +90,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
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-29 01:59:47 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2020-05-06 15:44:47 +08:00
|
|
|
index 0edba59675..7804cc0f6a 100644
|
2019-04-29 01:59:47 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2020-05-06 15:44:47 +08:00
|
|
|
@@ -882,12 +882,23 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
2019-04-29 01:59:47 +08:00
|
|
|
chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
|
|
|
|
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
|
2019-05-31 07:54:25 +08:00
|
|
|
|
|
|
|
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
|
2019-04-29 01:59:47 +08:00
|
|
|
+ final int finalChunkRange = chunkRange; // Paper for lambda below
|
2019-05-31 07:54:25 +08:00
|
|
|
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
|
2019-04-29 01:59:47 +08:00
|
|
|
// Spigot end
|
2019-06-25 09:47:58 +08:00
|
|
|
long i = chunkcoordintpair.pair();
|
2019-04-29 01:59:47 +08:00
|
|
|
|
2019-07-20 12:01:24 +08:00
|
|
|
return !this.chunkDistanceManager.d(i) ? true : this.playerMap.a(i).noneMatch((entityplayer) -> {
|
2019-05-13 06:34:42 +08:00
|
|
|
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
|
2019-04-29 01:59:47 +08:00
|
|
|
+ // Paper start -
|
2019-06-06 13:13:00 +08:00
|
|
|
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
|
|
|
|
+ double blockRange = 16384.0D;
|
|
|
|
+ if (reducedRange) {
|
2020-03-01 07:39:00 +08:00
|
|
|
+ event = entityplayer.playerNaturallySpawnedEvent;
|
|
|
|
+ if (event == null || event.isCancelled()) return false;
|
2019-06-06 13:13:00 +08:00
|
|
|
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot
|
2019-04-29 01:59:47 +08:00
|
|
|
+ // Paper end
|
|
|
|
});
|
|
|
|
}
|
2019-05-13 06:34:42 +08:00
|
|
|
|
2019-04-29 01:59:47 +08:00
|
|
|
--
|
2020-05-06 15:44:47 +08:00
|
|
|
2.26.0
|
2019-04-29 01:59:47 +08:00
|
|
|
|