Skip to content

Add MonsterEggSpawnEvent#4184

Closed
Proximyst wants to merge 1 commit intoPaperMC:masterfrom
Proximyst:pr-1981
Closed

Add MonsterEggSpawnEvent#4184
Proximyst wants to merge 1 commit intoPaperMC:masterfrom
Proximyst:pr-1981

Conversation

@Proximyst
Copy link
Contributor

Updated #1981.

@Proximyst Proximyst requested a review from a team as a code owner August 23, 2020 16:48
@Proximyst Proximyst requested a review from MiniDigger August 24, 2020 14:08
MiniDigger
MiniDigger previously approved these changes Aug 24, 2020
@kashike kashike added the type: feature Request for a new Feature. label Aug 24, 2020
@Proximyst Proximyst changed the base branch from progress/1.16.2 to master August 26, 2020 13:52
@Proximyst Proximyst dismissed MiniDigger’s stale review August 26, 2020 13:52

The base branch was changed.

+
+ // 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@yannicklamprecht yannicklamprecht Jan 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. create entity
  2. throw monster egg event
  3. 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@chickeneer chickeneer Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. :)

Copy link
Contributor

@chickeneer chickeneer Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! 😄

@stale
Copy link

stale bot commented Mar 3, 2021

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.

@stale
Copy link

stale bot commented Mar 10, 2021

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.

@stale stale bot closed this Mar 10, 2021
@Machine-Maker
Copy link
Member

I think this is still valid?

@MiniDigger
Copy link
Member

@Proximyst do you wanna revive this one?

@Proximyst
Copy link
Contributor Author

It'll stay stale for a bit probably, but eventually sure :)

@Proximyst Proximyst reopened this Mar 10, 2021
@stale stale bot removed the resolution: stale label Mar 10, 2021
@Proximyst Proximyst added the status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. label Mar 10, 2021
@Proximyst Proximyst requested a review from a team as a code owner June 20, 2021 12:00
@Owen1212055
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. status: rebase required type: feature Request for a new Feature.

9 participants