Add MonsterEggSpawnEvent#4184
Add MonsterEggSpawnEvent#4184Proximyst wants to merge 1 commit intoPaperMC:masterfrom Proximyst:pr-1981
Conversation
| + | ||
| + // Paper start - MonsterEggSpawnEvent | ||
| + if (spawnReason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG && itemstack != null && t0 != null) { | ||
| + MonsterEggSpawnEvent event = new MonsterEggSpawnEvent(entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, (org.bukkit.entity.LivingEntity) t0.getBukkitEntity(), itemstack.asBukkitCopy()); |
There was a problem hiding this comment.
This handling seems flawed if something hits something which adds the entity to the world before something calls setEntity, etc, should remove the original entity ref too
There was a problem hiding this comment.
Creating one seems to be sufficient. Why spawning an entity in world if you remove it the same second again on cancel?
So this should be fine:
- create entity
- throw monster egg event
- if not cancelled add it to world which results into a normal spawn event
Shouldn't something like this work?
@Nullable
public Entity spawnCreature(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
// Paper start
if (itemstack != null && entityhuman != null) {
T t0 = this.createCreature(worldserver, itemstack.getTag(), itemstack != null && itemstack.hasName() ? itemstack.getName() : null, entityhuman, blockposition, enummobspawn, flag, flag1);
if (t0 != null) {
io.papermc.paper.event.entity.MonsterEggSpawnEvent monsterEggSpawnEvent = new io.papermc.paper.event.entity.MonsterEggSpawnEvent(
entityhuman.getBukkitEntity(), t0.getBukkitEntity(), itemstack.asBukkitCopy());
if (monsterEggSpawnEvent.callEventIfRegistered()) {
Entity t1 = ((org.bukkit.craftbukkit.entity.CraftEntity)monsterEggSpawnEvent.getEntity()).getHandle();
worldserver.addAllEntities(t1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
return !t1.dead ? t1 : null; // Don't return an entity when CreatureSpawnEvent is canceled
// CraftBukkit end
}
}
}
// Paper end
return this.spawnCreature(worldserver, itemstack == null ? null : itemstack.getTag(), itemstack != null && itemstack.hasName() ? itemstack.getName() : null, entityhuman, blockposition, enummobspawn, flag, flag1);
}Why allow setting of the Entity? If you want to spawn a totally different entity, just cancel the event and spawn your different entity yourself using api.
There was a problem hiding this comment.
Because there are many interactions which plugin can do easily which can add an entity to the world before expected, e.g. teleporting the entity will add it to the world
There was a problem hiding this comment.
In Empirecraft's version of this event - we also check for || spawnReason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG.
Not sure why this was not included when porting.
https://github.com/starlis/empirecraft/blob/3718e17875c3389709c538437758f61929e8dfdc/patches/server/0013-MonsterEggSpawn-Event.patch#L58
For our fork's usage, although .setEntity() is implemented. We actually don't use it in our plugin, and I don't know believe that we ever had (so never got the indicated issues with it). The primary purpose was to make the spawning itemstack available at the time of spawning, so the entity could be modified based on data in the itemstack. And also cancelling.
I would note that, with setEntity excluded - this patch is very stable. With its regular use since 2013. :)
There was a problem hiding this comment.
I will add on. That I am willing to help update this PR to be mergeable in the upcoming week due to my familiarity with it. I have a Spring break this next week starting Friday! 😄
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically closed because it has not had activity in a long time. If the issue still applies to the most recent supported version, please open a new issue referencing this original issue. |
|
I think this is still valid? |
|
@Proximyst do you wanna revive this one? |
|
It'll stay stale for a bit probably, but eventually sure :) |
|
Closing as the author is no longer active at Paper. Thanks for all your work. 😄 If someone is interested in picking up on the work done here, feel free to open a separate PR. |
Updated #1981.