Add OMINOUS_ITEM_SPAWNER SpawnReason (#10897)

This commit is contained in:
Jakub Zacek 2024-07-15 23:35:51 +02:00 committed by GitHub
parent b57b24d549
commit 2cd8c461af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
264 changed files with 134 additions and 107 deletions

View file

@ -1,15 +1,17 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 24 Mar 2019 00:21:23 -0400
Subject: [PATCH] Entity#getEntitySpawnReason
Allows you to return the SpawnReason for why an Entity Spawned
Subject: [PATCH] Fixes and additions to the spawn reason API
Expose an entities spawn reason on the entity.
Pre existing entities will return NATURAL if it was a non
persistenting Living Entity, SPAWNER for spawners,
or DEFAULT since data was not stored.
Additionally, add missing spawn reasons.
Co-authored-by: Aurora <aurora@relanet.eu>
Co-authored-by: Jakub Zacek <dawon@dawon.eu>
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 99e1f17fddf9cebe7057998d1635804c55f18312..c3387a88a16cfd9157ade5d8a06eae2540a97288 100644
@ -27,3 +29,20 @@ index 99e1f17fddf9cebe7057998d1635804c55f18312..c3387a88a16cfd9157ade5d8a06eae25
+ org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason();
// Paper end
}
diff --git a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java
index 15cb5ea4b68eca070f73d2b899543274415ad240..2de81ee445824562aec7b52b7369b75280aab959 100644
--- a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java
+++ b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java
@@ -206,6 +206,12 @@ public class CreatureSpawnEvent extends EntitySpawnEvent {
* When a creature is spawned by an enchantment
*/
ENCHANTMENT,
+ // Paper start - Fixes and additions to the SpawnReason API
+ /**
+ * When an entity spawns from an ominous item spawner
+ */
+ OMINOUS_ITEM_SPAWNER,
+ // Paper end - Fixes and additions to the SpawnReason API
/**
* When a creature is spawned by plugins
*/

View file

@ -1,14 +1,18 @@
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
Subject: [PATCH] Fixes and additions to the spawn reason API
Expose an entities spawn reason on the entity.
Pre existing entities will return NATURAL if it was a non
persistenting Living Entity, SPAWNER for spawners,
or DEFAULT since data was not stored.
Additionally, add missing spawn reasons.
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Doc <nachito94@msn.com>
diff --git a/src/main/java/net/minecraft/server/commands/SummonCommand.java b/src/main/java/net/minecraft/server/commands/SummonCommand.java
index bf72cf288ade52ee8cc41ca978f368b3ad575951..798999be50d26be357ef3c6d5b9383ce4d1048c1 100644
--- a/src/main/java/net/minecraft/server/commands/SummonCommand.java
@ -107,6 +111,45 @@ index 2e376b0b2bf2d49ad0669b6e6fd287628a72ea64..869cd3723c6704e7512f4637682476b8
// Paper end
} catch (Throwable throwable) {
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 69a661f01e43d17262fd2845dde5528416bbe456..c0062c8f83641ff30e79a309c0bb9930ba4b422a 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -366,7 +366,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
@Nullable
public T spawn(ServerLevel world, @Nullable ItemStack stack, @Nullable Player player, BlockPos pos, MobSpawnType spawnReason, boolean alignPosition, boolean invertY) {
// CraftBukkit start
- return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+ return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, spawnReason == MobSpawnType.DISPENSER ? org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DISPENSE_EGG : org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // Paper - use correct spawn reason for dispenser spawn eggs
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java b/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
index 146cbec9e64b6c77759aadd0d0c4e989018e9aef..4c4545b3732d4c08afdb7bc1913169a96e82825c 100644
--- a/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
+++ b/src/main/java/net/minecraft/world/entity/OminousItemSpawner.java
@@ -89,7 +89,7 @@ public class OminousItemSpawner extends Entity {
entity = new ItemEntity(level, this.getX(), this.getY(), this.getZ(), itemStack);
}
- level.addFreshEntity(entity);
+ level.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.OMINOUS_ITEM_SPAWNER); // Paper - Fixes and additions to the SpawnReason API
level.levelEvent(3021, this.blockPosition(), 1);
level.gameEvent(entity, GameEvent.ENTITY_PLACE, this.position());
this.setItem(ItemStack.EMPTY);
diff --git a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
index 1dade7a4fbdf190661e4431496349444467509cc..3e869620db35d38db39fbeed715b898ef9d2743c 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
@@ -65,7 +65,7 @@ public class DragonFireball extends AbstractHurtingProjectile {
if (new com.destroystokyo.paper.event.entity.EnderDragonFireballHitEvent((org.bukkit.entity.DragonFireball) this.getBukkitEntity(), list.stream().map(LivingEntity::getBukkitLivingEntity).collect(java.util.stream.Collectors.toList()), (org.bukkit.entity.AreaEffectCloud) entityareaeffectcloud.getBukkitEntity()).callEvent()) { // Paper - EnderDragon Events
this.level().levelEvent(2006, this.blockPosition(), this.isSilent() ? -1 : 1);
- this.level().addFreshEntity(entityareaeffectcloud);
+ this.level().addFreshEntity(entityareaeffectcloud, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EXPLOSION); // Paper - use correct spawn reason
} else entityareaeffectcloud.discard(null); // Paper - EnderDragon Events
this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
}
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index ee897b8c9462dbb3d7be9a2994753155065ce205..1d0964a7f544735a0213d5c7832c71f53db139a9 100644
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
@ -119,6 +162,32 @@ index ee897b8c9462dbb3d7be9a2994753155065ce205..1d0964a7f544735a0213d5c7832c71f5
flag = true; // Paper
// CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
diff --git a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
index 211b7809f099678bc3bd64bd29fd9c4d19e3ab0d..b968129b9a93fdf771caba5f768456070543ba6a 100644
--- a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
@@ -111,7 +111,7 @@ public class FrogspawnBlock extends Block {
int k = random.nextInt(1, 361);
tadpole.moveTo(d, (double)pos.getY() - 0.5, e, (float)k, 0.0F);
tadpole.setPersistenceRequired();
- world.addFreshEntity(tadpole);
+ world.addFreshEntity(tadpole, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
index 1eda49c9ce8ee009cb08b18f02f59b37c2118628..14a5cd54820243f4ca59857b0d67c1e86457d590 100644
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
@@ -73,7 +73,7 @@ public class SnifferEggBlock extends Block {
Vec3 vec3 = pos.getCenter();
sniffer.setBaby(true);
sniffer.moveTo(vec3.x(), vec3.y(), vec3.z(), Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F);
- world.addFreshEntity(sniffer);
+ world.addFreshEntity(sniffer, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
index dbc0b69603dcffbf3d41d79719aa0f2b7da4a131..dd86f5ec5b2051aeea4e19ff97146362b1e8d019 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java

View file

@ -1,61 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 25 Sep 2022 11:21:01 -0700
Subject: [PATCH] Fixes and additions to the SpawnReason API
Fixes some wrong reasons, and adds missing spawn reasons for entities.
Co-authored-by: Doc <nachito94@msn.com>
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 69a661f01e43d17262fd2845dde5528416bbe456..c0062c8f83641ff30e79a309c0bb9930ba4b422a 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -366,7 +366,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
@Nullable
public T spawn(ServerLevel world, @Nullable ItemStack stack, @Nullable Player player, BlockPos pos, MobSpawnType spawnReason, boolean alignPosition, boolean invertY) {
// CraftBukkit start
- return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+ return this.spawn(world, stack, player, pos, spawnReason, alignPosition, invertY, spawnReason == MobSpawnType.DISPENSER ? org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DISPENSE_EGG : org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // Paper - use correct spawn reason for dispenser spawn eggs
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
index 1dade7a4fbdf190661e4431496349444467509cc..3e869620db35d38db39fbeed715b898ef9d2743c 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/DragonFireball.java
@@ -65,7 +65,7 @@ public class DragonFireball extends AbstractHurtingProjectile {
if (new com.destroystokyo.paper.event.entity.EnderDragonFireballHitEvent((org.bukkit.entity.DragonFireball) this.getBukkitEntity(), list.stream().map(LivingEntity::getBukkitLivingEntity).collect(java.util.stream.Collectors.toList()), (org.bukkit.entity.AreaEffectCloud) entityareaeffectcloud.getBukkitEntity()).callEvent()) { // Paper - EnderDragon Events
this.level().levelEvent(2006, this.blockPosition(), this.isSilent() ? -1 : 1);
- this.level().addFreshEntity(entityareaeffectcloud);
+ this.level().addFreshEntity(entityareaeffectcloud, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EXPLOSION); // Paper - use correct spawn reason
} else entityareaeffectcloud.discard(null); // Paper - EnderDragon Events
this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
}
diff --git a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
index 3c4949965c0fad3c6200d0fd1e31ebe844ba6e0e..f2d4264743b6070f36adb66d00a3de0a72b86846 100644
--- a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java
@@ -117,7 +117,7 @@ public class FrogspawnBlock extends Block {
int k = random.nextInt(1, 361);
tadpole.moveTo(d, (double)pos.getY() - 0.5, e, (float)k, 0.0F);
tadpole.setPersistenceRequired();
- world.addFreshEntity(tadpole);
+ world.addFreshEntity(tadpole, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
index 38288f20306632e6546c95b4cb1a42806be49975..f53808e200bd83ab80954ec5c1e9c14250302be8 100644
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
@@ -87,7 +87,7 @@ public class SnifferEggBlock extends Block {
Vec3 vec3 = pos.getCenter();
sniffer.setBaby(true);
sniffer.moveTo(vec3.x(), vec3.y(), vec3.z(), Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F);
- world.addFreshEntity(sniffer);
+ world.addFreshEntity(sniffer, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper - use correct spawn reason
}
}
}

View file

@ -6,7 +6,7 @@ Subject: [PATCH] fix Instruments
properly handle Player#playNote
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 90ce5c386d46f10e14df67953938168c29d24c6a..6503bce4c0281619489adc01fa1da0c59b433875 100644
index 02b9233ecf929ac9ec7d304231d8bc66fc00dad4..682c5e9328d965bf335bb06ac7aedf6d49b1c6cb 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -768,7 +768,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View file

@ -7,7 +7,7 @@ Subject: [PATCH] Win Screen API
public net.minecraft.server.level.ServerPlayer seenCredits
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 207e72cad59a07c0750e9303dd21519c83ab2358..ee5d93cd0c7ea7376e8488265d4e21610edeedc2 100644
index 4bcceef859099405a3d78bc7e6b12c778e906d72..d0cd2a8c99d607e36d37718b9e2c439f4a939535 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1305,6 +1305,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View file

@ -16,7 +16,7 @@ with less than zero amounts, so this code doesn't create
a problem with operations on the vanilla ItemStack.
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index a147b54668854668b02bbe39c9eae22bb98dc217..8d7e7e831792422d6e9f3210496c577fb64d597f 100644
index 8468bf6676b7ade3508085f44fac8980a8c6081e..c57051b35cb42d986833030655a63b9dff3c29bb 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -163,7 +163,7 @@ public final class CraftItemStack extends ItemStack {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Fix force-opening enchantment tables
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 79faf3c64891899bf5d6d119154aba02d4665b3b..e1150d36de56466ad9fdd5f2cdb4c30855d4af70 100644
index 0213898b4d029ea9260a755d6411d909a1b6885c..9ab3fc287480aedcb4033801d4f092719e933454 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -403,7 +403,18 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Fix spigot sound playing for BlockItem ItemStacks
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 96a7e80e3efab1bf626fb7aff61e095ca09789d4..f0b166a7fbeb222b97b5f2770c20d98df5d9bcc8 100644
index 57510b85caf8914290ab0afb89cfb773158715b8..8777e634a69825302da7ed5031a344b80724783e 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -571,7 +571,11 @@ public final class ItemStack implements DataComponentHolder {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Add event for player editing sign
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index f0b166a7fbeb222b97b5f2770c20d98df5d9bcc8..92be749721f26e9385e592a985db58cf05c67801 100644
index 8777e634a69825302da7ed5031a344b80724783e..a6ca820adf6e86f8358967d8d3b2e45cd1135b2c 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -550,7 +550,7 @@ public final class ItemStack implements DataComponentHolder {

View file

@ -17,7 +17,7 @@ index 78951f50188528718cdb3dbbaabe3f9f2760ffe3..7826e2a52da47914aca39fef958b8f39
}
}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 92be749721f26e9385e592a985db58cf05c67801..1f2e6f57ffb827ef9bf3623bfdde07db21edf6ee 100644
index a6ca820adf6e86f8358967d8d3b2e45cd1135b2c..780b2fada591fb1b504fbf4828c31ec0dd1c25db 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -466,6 +466,7 @@ public final class ItemStack implements DataComponentHolder {

View file

@ -81,7 +81,7 @@ index 1ef380cbd77132b743520f952afa8321042bec6d..7fe43ac849d3ee80c447e8c024ea39fd
// Special case: the axis is optional for ELECTRIC_SPARK
Preconditions.checkArgument(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for the %s effect", effect);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 85f403c07ff146a0da232ac7bfc0551a2fa2601b..296bb88ed34f499535ef0b9fdffa67b7de81c60b 100644
index 49e22acbcdcdb2108b360c2a6e40c752c12ab9f6..4c5249eab8e59b46c902f2cb65f90aa2a66a33d4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -917,7 +917,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

Some files were not shown because too many files have changed in this diff Show more