2019-03-20 01:46:00 +00:00
|
|
|
From 09c7a957235c78d328efac0b90a69a6f4c4749ce Mon Sep 17 00:00:00 2001
|
2018-01-14 22:02:38 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 14 Jan 2018 17:01:31 -0500
|
|
|
|
Subject: [PATCH] PreCreatureSpawnEvent
|
|
|
|
|
|
|
|
Adds an event to fire before an Entity is created, so that plugins that need to cancel
|
|
|
|
CreatureSpawnEvent can do so from this event instead.
|
|
|
|
|
|
|
|
Cancelling CreatureSpawnEvent rapidly causes a lot of garbage collection and CPU waste
|
|
|
|
as it's done after the Entity object has been fully created.
|
|
|
|
|
|
|
|
Mob Limiting plugins and blanket "ban this type of monster" plugins should use this event
|
|
|
|
instead and save a lot of server resources.
|
|
|
|
|
|
|
|
See: https://github.com/PaperMC/Paper/issues/917
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
2018-12-15 01:17:27 +00:00
|
|
|
index 027ba7191..eca3f85ad 100644
|
2018-01-14 22:02:38 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
+
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nullable;
|
2018-07-25 23:07:56 +00:00
|
|
|
@@ -94,6 +95,28 @@ public abstract class MobSpawnerAbstract {
|
2018-07-18 18:55:52 +00:00
|
|
|
double d3 = j >= 1 ? nbttaglist.k(0) : (double) blockposition.getX() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawnRange + 0.5D;
|
|
|
|
double d4 = j >= 2 ? nbttaglist.k(1) : (double) (blockposition.getY() + world.random.nextInt(3) - 1);
|
|
|
|
double d5 = j >= 3 ? nbttaglist.k(2) : (double) blockposition.getZ() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawnRange + 0.5D;
|
2018-01-14 22:02:38 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ if (this.getMobName() == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2018-01-16 04:44:21 +00:00
|
|
|
+ String key = this.getMobName().getKey();
|
|
|
|
+ org.bukkit.entity.EntityType type = org.bukkit.entity.EntityType.fromName(key);
|
|
|
|
+ if (type != null) {
|
|
|
|
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event;
|
|
|
|
+ event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
|
|
|
+ MCUtil.toLocation(world, d3, d4, d5),
|
|
|
|
+ type,
|
|
|
|
+ org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER
|
|
|
|
+ );
|
|
|
|
+ if (!event.callEvent()) {
|
2018-07-25 22:19:51 +00:00
|
|
|
+ flag = true;
|
2018-01-16 04:44:21 +00:00
|
|
|
+ if (event.shouldAbortSpawn()) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ continue;
|
2018-01-14 22:02:38 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
Entity entity = ChunkRegionLoader.a(nbttagcompound, world, d3, d4, d5, false);
|
|
|
|
|
|
|
|
if (entity == null) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2019-03-20 01:46:00 +00:00
|
|
|
index 2aa0db5c2..b57616960 100644
|
2018-01-14 22:02:38 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2018-10-22 23:16:21 +00:00
|
|
|
@@ -164,10 +164,30 @@ public final class SpawnerCreature {
|
2018-01-14 22:02:38 +00:00
|
|
|
|
2018-10-22 23:16:21 +00:00
|
|
|
if (worldserver.a(enumcreaturetype, biomebase_biomemeta, (BlockPosition) blockposition_mutableblockposition)) {
|
|
|
|
EntityPositionTypes.Surface entitypositiontypes_surface = EntityPositionTypes.a(biomebase_biomemeta.b);
|
2018-07-18 18:55:52 +00:00
|
|
|
-
|
2018-10-22 23:16:21 +00:00
|
|
|
if (entitypositiontypes_surface != null && a(entitypositiontypes_surface, worldserver, blockposition_mutableblockposition, biomebase_biomemeta.b)) {
|
|
|
|
EntityInsentient entityinsentient;
|
2018-07-18 18:55:52 +00:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event;
|
|
|
|
+ EntityTypes<? extends EntityInsentient> cls = biomebase_biomemeta.b;
|
|
|
|
+ org.bukkit.entity.EntityType type = EntityTypes.clsToTypeMap.get(cls);
|
|
|
|
+ if (type != null) {
|
|
|
|
+ event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
|
|
|
+ MCUtil.toLocation(worldserver, blockposition_mutableblockposition),
|
|
|
|
+ type, SpawnReason.NATURAL
|
|
|
|
+ );
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
+ if (event.shouldAbortSpawn()) {
|
2018-10-22 23:16:21 +00:00
|
|
|
+ continue label137; // right above the iterator for c (Chunk Pos Set)
|
2018-07-18 18:55:52 +00:00
|
|
|
+ }
|
|
|
|
+ j1 += l2;
|
|
|
|
+ ++j4;
|
|
|
|
+ continue;
|
2018-01-16 04:44:21 +00:00
|
|
|
+ }
|
2018-01-14 22:02:38 +00:00
|
|
|
+ }
|
2018-07-18 18:55:52 +00:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
+
|
2018-10-22 23:16:21 +00:00
|
|
|
try {
|
|
|
|
entityinsentient = (EntityInsentient) biomebase_biomemeta.b.a((World) worldserver);
|
|
|
|
} catch (Exception exception) {
|
2018-01-14 22:02:38 +00:00
|
|
|
--
|
2019-03-20 01:46:00 +00:00
|
|
|
2.21.0
|
2018-01-14 22:02:38 +00:00
|
|
|
|