2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-04-28 19:59:47 +02: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
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
2021-05-11 01:22:11 +02:00
|
|
|
index 9ed97d5db81e3603ccccca7500420d7e401ef2a5..b9bde85a90b429659e1a4ab111253cddd797368e 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
|
|
|
@@ -611,6 +611,15 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-03-01 00:39:00 +01:00
|
|
|
this.world.getMethodProfiler().exit();
|
2020-06-25 15:11:48 +02:00
|
|
|
//List<PlayerChunk> list = Lists.newArrayList(this.playerChunkMap.f()); // Paper
|
|
|
|
//Collections.shuffle(list); // Paper
|
2020-03-01 00:39:00 +01: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 15:11:48 +02:00
|
|
|
+ for (EntityPlayer entityPlayer : this.world.getPlayers()) {
|
2020-03-01 00:39:00 +01:00
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
|
|
|
|
+ entityPlayer.playerNaturallySpawnedEvent.callEvent();
|
|
|
|
+ };
|
|
|
|
+ // Paper end
|
2020-06-25 15:11:48 +02:00
|
|
|
this.playerChunkMap.f().forEach((playerchunk) -> { // Paper - no... just no...
|
|
|
|
Optional<Chunk> optional = ((Either) playerchunk.a().getNow(PlayerChunk.UNLOADED_CHUNK)).left();
|
2020-03-01 00:39:00 +01:00
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
|
2021-05-11 01:22:11 +02:00
|
|
|
index 09385eabefeb7d59de1ce4138648badd123396f9..3d517ab98da5fd56101e97b5678f7180839269f8 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
|
2020-03-01 00:39:00 +01:00
|
|
|
@@ -1,5 +1,6 @@
|
2021-03-16 08:19:45 +01:00
|
|
|
package net.minecraft.server.level;
|
2020-03-01 00:39:00 +01:00
|
|
|
|
|
|
|
+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-03-16 08:19:45 +01:00
|
|
|
@@ -227,6 +228,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2020-03-01 00:39:00 +01: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
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
2021-05-11 01:22:11 +02:00
|
|
|
index 1d71a19a7bbe463f537861531113dd1ed3e5b977..d1e45dfb99074ec027d4f943391a024c726d93b2 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
2021-05-11 01:22:11 +02:00
|
|
|
@@ -966,12 +966,23 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
2019-04-28 19:59:47 +02:00
|
|
|
chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
|
|
|
|
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
|
2019-05-31 01:54:25 +02:00
|
|
|
|
|
|
|
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
|
2019-04-28 19:59:47 +02:00
|
|
|
+ final int finalChunkRange = chunkRange; // Paper for lambda below
|
2019-05-31 01:54:25 +02:00
|
|
|
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
|
2019-04-28 19:59:47 +02:00
|
|
|
// Spigot end
|
2019-06-25 03:47:58 +02:00
|
|
|
long i = chunkcoordintpair.pair();
|
2019-04-28 19:59:47 +02:00
|
|
|
|
2019-07-20 06:01:24 +02:00
|
|
|
return !this.chunkDistanceManager.d(i) ? true : this.playerMap.a(i).noneMatch((entityplayer) -> {
|
2019-05-13 00:34:42 +02:00
|
|
|
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
|
2019-04-28 19:59:47 +02:00
|
|
|
+ // Paper start -
|
2019-06-06 07:13:00 +02:00
|
|
|
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
|
|
|
|
+ double blockRange = 16384.0D;
|
|
|
|
+ if (reducedRange) {
|
2020-03-01 00:39:00 +01:00
|
|
|
+ event = entityplayer.playerNaturallySpawnedEvent;
|
|
|
|
+ if (event == null || event.isCancelled()) return false;
|
2019-06-06 07:13:00 +02:00
|
|
|
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot
|
2019-04-28 19:59:47 +02:00
|
|
|
+ // Paper end
|
|
|
|
});
|
|
|
|
}
|
2019-05-13 00:34:42 +02:00
|
|
|
|