Paper/patches/server/0250-Add-PhantomPreSpawnEvent.patch
Spottedleaf 01a13871de
Rewrite chunk system (#8177)
Patch documentation to come

Issues with the old system that are fixed now:
- World generation does not scale with cpu cores effectively.
- Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps.
- Unreliable prioritisation of chunk gen/load calls that block the main thread.
- Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved.
- Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal.
- Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles.

The above list is not complete. The patch documentation will complete it.

New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil.

Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft.

The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 01:02:51 -07:00

97 Zeilen
5.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 25 Aug 2018 19:56:51 -0500
Subject: [PATCH] Add PhantomPreSpawnEvent
diff --git a/src/main/java/net/minecraft/world/entity/monster/Phantom.java b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
index c436476b3ec442b40a7ff122e6d3947a47ae163b..84400bb44d5deb7c79295a83c4c3c6aac88f3175 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Phantom.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
@@ -171,6 +171,11 @@ public class Phantom extends FlyingMob implements Enemy {
}
this.setPhantomSize(nbt.getInt("Size"));
+ // Paper start
+ if (nbt.hasUUID("Paper.SpawningEntity")) {
+ this.spawningEntity = nbt.getUUID("Paper.SpawningEntity");
+ }
+ // Paper end
}
@Override
@@ -180,6 +185,11 @@ public class Phantom extends FlyingMob implements Enemy {
nbt.putInt("AY", this.anchorPoint.getY());
nbt.putInt("AZ", this.anchorPoint.getZ());
nbt.putInt("Size", this.getPhantomSize());
+ // Paper start
+ if (this.spawningEntity != null) {
+ nbt.putUUID("Paper.SpawningEntity", this.spawningEntity);
+ }
+ // Paper end
}
@Override
@@ -231,6 +241,14 @@ public class Phantom extends FlyingMob implements Enemy {
return entitysize.scale(f);
}
+ // Paper start
+ java.util.UUID spawningEntity;
+
+ public java.util.UUID getSpawningEntity() {
+ return spawningEntity;
+ }
+ public void setSpawningEntity(java.util.UUID entity) { this.spawningEntity = entity; }
+ // Paper end
private static enum AttackPhase {
CIRCLE, SWOOP;
diff --git a/src/main/java/net/minecraft/world/level/levelgen/PhantomSpawner.java b/src/main/java/net/minecraft/world/level/levelgen/PhantomSpawner.java
index 573490a7c95746c3d372d258b2e592241258f6cf..e9d25aef08103ccdbc6a35c3ab67c1d921e9f45d 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/PhantomSpawner.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/PhantomSpawner.java
@@ -3,6 +3,7 @@ package net.minecraft.world.level.levelgen;
import java.util.Iterator;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.MCUtil;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.ServerStatsCounter;
@@ -71,8 +72,17 @@ public class PhantomSpawner implements CustomSpawner {
int k = 1 + randomsource.nextInt(difficultydamagescaler.getDifficulty().getId() + 1);
for (int l = 0; l < k; ++l) {
+ // Paper start
+ com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event = new com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent(MCUtil.toLocation(world, blockposition1), ((ServerPlayer) entityhuman).getBukkitEntity(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL);
+ if (!event.callEvent()) {
+ if (event.shouldAbortSpawn()) {
+ break;
+ }
+ continue;
+ }
+ // Paper end
Phantom entityphantom = (Phantom) EntityType.PHANTOM.create(world);
-
+ entityphantom.setSpawningEntity(entityhuman.getUUID()); // Paper
entityphantom.moveTo(blockposition1, 0.0F, 0.0F);
groupdataentity = entityphantom.finalizeSpawn(world, difficultydamagescaler, MobSpawnType.NATURAL, groupdataentity, (CompoundTag) null);
world.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
index f77b83bee6eb739220b55793a0807f0267cfc8a9..c9dab70b0b284fe1c1daafd3c1f5bd08b14fa35d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPhantom.java
@@ -34,4 +34,11 @@ public class CraftPhantom extends CraftFlying implements Phantom {
public EntityType getType() {
return EntityType.PHANTOM;
}
+
+ // Paper start
+ @Override
+ public java.util.UUID getSpawningEntity() {
+ return getHandle().getSpawningEntity();
+ }
+ // Paper end
}