-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Minor
-
None
-
Affects Version/s: None
-
None
-
1.20.1-R0.1-SNAPSHOT
-
Yes
When a player who has parrot on his/her shoulders jumps or gets damaged, the entities (which are always parrots, but it doesnt matter) will be removed from his/her shoulders.
That will trigger
removeEntitiesOnShoulder() method in Spigot\Spigot-Server\src\main\java\net\minecraft\world\entity\player\EntityHuman.java.
//代码占位符 protected void removeEntitiesOnShoulder() { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { // CraftBukkit start if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) { this.setShoulderEntityLeft(new NBTTagCompound()); } if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) { this.setShoulderEntityRight(new NBTTagCompound()); } // CraftBukkit end } }
But until now there hasnt been a good way to prevent this method being triggered. So its required to create an event for it.
//代码占位符 protected void removeEntitiesOnShoulder() { PlayerRemoveEntitiesOnShoulderEvent event = new PlayerDropItemEvent(this, entityOnLeftShoulder, entityOnRightShoulder); this.level().getCraftServer().getPluginManager().callEvent(event); if (!event.isCancelled && this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { // CraftBukkit start if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) { this.setShoulderEntityLeft(new NBTTagCompound()); } if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) { this.setShoulderEntityRight(new NBTTagCompound()); } // CraftBukkit end } }
This event requires:
getPlayer() - return the HumanEntity
getEntityOnLeftShoulder() - return the entity on the left shoulder (null if nothing)
getEntityOnRightShoulder() - return the entity on the right shoulder (null if nothing)
isCancelled() - return whether canncelled
setCancelled() - set the event canncelled or not