mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
Call PreCreatureSpawnEvent for more spawn reasons (#5201)
This commit is contained in:
parent
20e500fadc
commit
bcb2a139ee
@ -14,6 +14,57 @@ 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/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
@@ -0,0 +0,0 @@ public class EntityTypes<T extends Entity> {
|
||||
|
||||
@Nullable
|
||||
public T spawnCreature(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||
+ // Paper start - Call PreCreatureSpawnEvent
|
||||
+ org.bukkit.entity.EntityType type = org.bukkit.entity.EntityType.fromName(EntityTypes.getName(this).getKey());
|
||||
+ if (type != null) {
|
||||
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event;
|
||||
+ event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
||||
+ MCUtil.toLocation(worldserver, blockposition),
|
||||
+ type,
|
||||
+ spawnReason
|
||||
+ );
|
||||
+ if (!event.callEvent()) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end
|
||||
T t0 = this.createCreature(worldserver, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1);
|
||||
|
||||
if (t0 != null) {
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityVillager.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
|
||||
@@ -0,0 +0,0 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
||||
BlockPosition blockposition1 = this.a(blockposition, d0, d1);
|
||||
|
||||
if (blockposition1 != null) {
|
||||
+ // Paper start - Call PreCreatureSpawnEvent
|
||||
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event;
|
||||
+ event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
||||
+ MCUtil.toLocation(world, blockposition1),
|
||||
+ org.bukkit.entity.EntityType.IRON_GOLEM,
|
||||
+ org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE
|
||||
+ );
|
||||
+ if (!event.callEvent()) {
|
||||
+ if (event.shouldAbortSpawn()) {
|
||||
+ SensorGolemLastSeen.b(this); // Set Golem Last Seen to stop it from spawning another one
|
||||
+ return null;
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+ // Paper end
|
||||
EntityIronGolem entityirongolem = (EntityIronGolem) EntityTypes.IRON_GOLEM.createCreature(worldserver, (NBTTagCompound) null, (IChatBaseComponent) null, (EntityHuman) null, blockposition1, EnumMobSpawn.MOB_SUMMONED, false, false);
|
||||
|
||||
if (entityirongolem != null) {
|
||||
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
||||
@ -46,6 +97,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
Entity entity = EntityTypes.a(nbttagcompound, world, (entity1) -> {
|
||||
entity1.setPositionRotation(d3, d4, d5, entity1.yaw, entity1.pitch);
|
||||
return entity1;
|
||||
diff --git a/src/main/java/net/minecraft/server/SensorGolemLastSeen.java b/src/main/java/net/minecraft/server/SensorGolemLastSeen.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/SensorGolemLastSeen.java
|
||||
+++ b/src/main/java/net/minecraft/server/SensorGolemLastSeen.java
|
||||
@@ -0,0 +0,0 @@ public class SensorGolemLastSeen extends Sensor<EntityLiving> {
|
||||
Optional<List<EntityLiving>> optional = entityliving.getBehaviorController().getMemory(MemoryModuleType.MOBS);
|
||||
|
||||
if (optional.isPresent()) {
|
||||
- boolean flag = ((List) optional.get()).stream().anyMatch((entityliving1) -> {
|
||||
+ boolean flag = optional.get().stream().anyMatch((entityliving1) -> { // Paper - decompile fixes
|
||||
return entityliving1.getEntityType().equals(EntityTypes.IRON_GOLEM);
|
||||
});
|
||||
|
||||
@@ -0,0 +0,0 @@ public class SensorGolemLastSeen extends Sensor<EntityLiving> {
|
||||
}
|
||||
}
|
||||
|
||||
+ public static void setDetectedRecently(EntityLiving entityLiving) { b(entityLiving); } // Paper - OBFHELPER
|
||||
public static void b(EntityLiving entityliving) {
|
||||
entityliving.getBehaviorController().a(MemoryModuleType.GOLEM_DETECTED_RECENTLY, true, 600L);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||
|
Loading…
Reference in New Issue
Block a user