Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add ItemSpawnEntityEvent and BlockPlaceEntityEvent and expand EntityPlaceEvent

Open Machine-Maker opened this issue 3 years ago • 15 comments
trafficstars

WIP so far, still adding spots these events should be called, but should be a catch-all now for non-hanging entities spawned as a result of item "placement".

Resolves https://github.com/PaperMC/Paper/issues/4795 Resolves https://github.com/PaperMC/Paper/issues/6898 Supersedes https://github.com/PaperMC/Paper/pull/4184

Changes

Adds ItemSpawnEntityEvent Adds PlaceEntityEvent (extends ItemSpawnEntityEvent) Adds BlockPlaceEntityEvent (extends PlaceEntityEvent) Makes EntityPlaceEvent extend PlaceEntityEvent

Added an ItemStack field on ItemSpawnEntityEvent since that applies to all uses of that event and EntityPlaceEvent.

New Event Calls

ItemSpawnEntityEvent
  • Spawn eggs from dispensers and players
EntityPlaceEvent (player only)
  • mob eggs from players
BlockPlaceEntityEvent (dispenser only)
  • boats
  • armor stand
  • mob buckets
  • tnt
### Entity Placements
- [x] Spawn Eggs - ItemSpawnEntityEvent (dispenser w/null player)
- [x] Boats - EntityPlaceEvent/BlockPlaceEntityEvent
- [x] ~~Item Frame, Painting, Leash~~ (HangingPlaceEvent) (can't change due to API break)
- [x] Armor Stand - EntityPlaceEvent/BlockPlaceEntityEvent
- [x] End Crystals - EntityPlaceEvent
- [x] Fish Buckets - EntityPlaceEvent/BlockPlaceEntityEvent
- [x] ~~Fireworks~~ already tracks its spawning stack and shooter
- [x] ~~Fire Charges~~ already tracks its spawning stack and shooter
- [x] PrimedTNT BlockPlaceEntityEvent

Machine-Maker avatar Jan 20 '22 18:01 Machine-Maker

This is not the same as https://github.com/PaperMC/Paper/pull/4184?

molor avatar Jan 25 '22 13:01 molor

@molor a couple differences with that

  1. Its type inhertiance doesn't integerate with EntityPlaceEvent
  2. this provides access to the blockface
  3. no "entity setter", that really doesn't make sense with how the API deals with entities IMO
  4. This PR expands EntityPlaceEvent in addition to adding a new event

Machine-Maker avatar Jan 25 '22 19:01 Machine-Maker

This would probably also close #6898, at least in regards to what I initially wanted to achieve.

aerulion avatar Feb 23 '22 23:02 aerulion

Something I'm not sure about, are fire charges from dispeners? those technically do spawn an entity from an itemstack. but its different because a player can't do the same thing.

Machine-Maker avatar Mar 04 '22 02:03 Machine-Maker

I would say the event should be called in this case, as it otherwise would be inconsistent to call the events for something like fireworks and spawn eggs, but not for fire charges. And to me it would be more likely for someone wanting to modify the dispensed fire charge, then someone wondering why there's always a null player on an entity which cannot be "summoned" by a player.

aerulion avatar Mar 04 '22 02:03 aerulion

Ok, that makes sense, but should it be EntityPlaceEvent or ItemSpawnEntityEvent? I’m leaning to EntityPlaceEvent even tho it’s more of a launch. (Like fireworks I guess)

Machine-Maker avatar Mar 04 '22 03:03 Machine-Maker

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[bot] avatar May 30 '22 21:05 stale[bot]

I've decided against adding Fire Charges and fireworks. I don't want to add any projectiles. They already have api that tracks their spawning stack and shooter. I did add PrimedTNT to the list, since a dispenser is placing that and its creating an entity.

Machine-Maker avatar Jun 24 '22 02:06 Machine-Maker

Rebased for 1.19

Machine-Maker avatar Jul 22 '22 18:07 Machine-Maker

Rebased and updated for 1.19.3. Reworked things a big to keep EntityPlaceEvent a player-only event.

Machine-Maker avatar Dec 13 '22 07:12 Machine-Maker

This can consider the staled #6487 ? its like the #6898 created later.. mostly for the Wither/Golems created using blocks detect how and who build (for avoid things like try listen place blocks and spawn for try make that)

Doc94 avatar Aug 27 '23 15:08 Doc94

Rebased for 1.20.4

Machine-Maker avatar Dec 30 '23 06:12 Machine-Maker

gave this a look over as much as I can with my level of sleep and sight, overall looks fine of what I've seen

electronicboy avatar Dec 30 '23 06:12 electronicboy

Rebased for 1.20.6

Machine-Maker avatar May 13 '24 04:05 Machine-Maker

Half a year has passed. Has this PR been forgotten? Up to now, there is still a lack of an event for tracking the generation of fish by using buckets.

Noogear avatar Nov 25 '24 13:11 Noogear