PocketMine-MP icon indicating copy to clipboard operation
PocketMine-MP copied to clipboard

Added entity middle-click feature

Open JavierLeon9966 opened this issue 1 year ago • 3 comments

Introduction

Added entity middle-click feature, this is a vanilla feature that it hasn't been implemented for so long.

Relevant issues

  • Closes #4766

Changes

API changes

Added the following methods in Entity:

  • Entity->getCleanedNBT(): Returns a cleaned NBT from the entity, removing tags such as position, motion, etc.
  • Entity->copyDataFromItem(): Copies the entity NBT from the item into the entity (internal).
  • Entity->getSpawnItem(): Returns the item that can be used to spawn the entity, by default it returns air if there isn't one.
  • Entity->getPickedItem(): Returns an item that is able to spawn said entity, with a parameter $addUserData to include the entity's NBT.

Added the following methods in Item:

  • Item->clearCustomEntityData(): Clears the NBT from the picked (middle-clicked) entity.
  • Item->setCustomEntityData(): Sets the NBT of the picked (middle-clicked) entity.
  • Item->getCustomEntityData(): Returns the NBT of the picked (middle-clicked) entity.

Added the following method in Player:

  • Player->pickEntity(): Equips the middle-clicked (picked) entity in the player's hand with added NBT if requested.

Added the following event:

  • PlayerEntityPickEvent

Tests

https://clipchamp.com/watch/nrP09ZXooey

JavierLeon9966 avatar Nov 07 '22 02:11 JavierLeon9966

I'd prefer this wasn't dependent on NBT. Bad enough that we have to deal with that for tiles already...

dktapps avatar Nov 07 '22 13:11 dktapps

@JavierLeon9966 any updates for this PR? If not it will be closed when API 5 releases

jasonw4331 avatar Mar 17 '23 15:03 jasonw4331

Oh, whoops, I forgot about it, but I think I have the changes in my local

JavierLeon9966 avatar Mar 17 '23 15:03 JavierLeon9966