Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
ef0e5a642d
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 9ae3f10f SPIGOT-3842: Add Player#fireworkBoost() and expand Firework API 48c0c547 PR-786: Add methods to get sounds from entities CraftBukkit Changes: 5cc9c022a SPIGOT-7152: Handle hand item changing during air interact event 4ffa1acf6 SPIGOT-7154: Players get kicked when interacting with a conversation 4daa21123 SPIGOT-3842: Add Player#fireworkBoost() and expand Firework API e5d6a9bbf PR-1100: Add methods to get sounds from entities b7e9f1c8b SPIGOT-7146: Reduce use of Material switch in ItemMeta Spigot Changes: 4c157bb4 Rebuild patches
122 Zeilen
6.6 KiB
Diff
122 Zeilen
6.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 24 Mar 2019 00:24:52 -0400
|
|
Subject: [PATCH] Entity#getEntitySpawnReason
|
|
|
|
Allows you to return the SpawnReason for why an Entity Spawned
|
|
|
|
Pre existing entities will return NATURAL if it was a non
|
|
persistenting Living Entity, SPAWNER for spawners,
|
|
or DEFAULT since data was not stored.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 377ebed70c5008d69701bd919f22ad4506dd129c..427dfb5c7fe09e94aae617ecc1440fd1530fb857 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1215,6 +1215,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
return true;
|
|
}
|
|
// Paper end
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
|
if (entity.isRemoved()) {
|
|
// Paper start
|
|
if (DEBUG_ENTITIES) {
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 3cb257544d95e82f8de2d693f510c15980aa27c8..895d087fbdde840bd6b96b6c8d231fc9beeb2a0b 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -348,7 +348,7 @@ public abstract class PlayerList {
|
|
// CraftBukkit start
|
|
ServerLevel finalWorldServer = worldserver1;
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
|
|
- return !finalWorldServer.addWithUUID(entity1) ? null : entity1;
|
|
+ return !finalWorldServer.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // Paper
|
|
// CraftBukkit end
|
|
});
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 424eed2daa3a9574cf1179a7f970f1565ea5fc71..a2a607e6ae867a4cabe1c2280154c99e93d0e7e9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -74,6 +74,8 @@ import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.Nameable;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
+import net.minecraft.world.entity.animal.AbstractFish;
|
|
+import net.minecraft.world.entity.animal.Animal;
|
|
import net.minecraft.world.entity.item.ItemEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
|
@@ -231,6 +233,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
}
|
|
// Paper end
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
|
private CraftEntity bukkitEntity;
|
|
@@ -1971,6 +1974,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
|
}
|
|
+ if (spawnReason != null) {
|
|
+ nbt.putString("Paper.SpawnReason", spawnReason.name());
|
|
+ }
|
|
// Save entity's from mob spawner status
|
|
if (spawnedViaMobSpawner) {
|
|
nbt.putBoolean("Paper.FromMobSpawner", true);
|
|
@@ -2116,6 +2122,26 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
|
|
spawnedViaMobSpawner = nbt.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
|
|
+ if (nbt.contains("Paper.SpawnReason")) {
|
|
+ String spawnReasonName = nbt.getString("Paper.SpawnReason");
|
|
+ try {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
|
|
+ } catch (Exception ignored) {
|
|
+ LOGGER.error("Unknown SpawnReason " + spawnReasonName + " for " + this);
|
|
+ }
|
|
+ }
|
|
+ if (spawnReason == null) {
|
|
+ if (spawnedViaMobSpawner) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER;
|
|
+ } else if (this instanceof Mob && (this instanceof Animal || this instanceof AbstractFish) && !((Mob) this).removeWhenFarAway(0.0)) {
|
|
+ if (!nbt.getBoolean("PersistenceRequired")) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (spawnReason == null) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
|
|
+ }
|
|
// Paper end
|
|
|
|
} catch (Throwable throwable) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
index 0be0c7a323277093a6f8e476048eb9ee8712cbc9..c7e97263eee005fd673882e11c436542cb0ca62a 100644
|
|
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
@@ -181,6 +181,7 @@ public abstract class BaseSpawner {
|
|
// Spigot End
|
|
}
|
|
entity.spawnedViaMobSpawner = true; // Paper
|
|
+ entity.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER; // Paper
|
|
flag = true; // Paper
|
|
// Spigot Start
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index 2a4f26c5bae66121c5c21d7f1013b3b7753608a4..3bda8128c2956d817677e28ff87c9c5ed61c8bd2 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1266,5 +1266,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
public boolean fromMobSpawner() {
|
|
return getHandle().spawnedViaMobSpawner;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
+ return getHandle().spawnReason;
|
|
+ }
|
|
// Paper end
|
|
}
|