mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
Player: check if the item meaningfully changed before discarding it in creative
fixes #5220
This commit is contained in:
parent
1c6a2b66f7
commit
db7cee6f22
@ -1473,15 +1473,27 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
*/
|
||||
private function returnItemsFromAction(Item $oldHeldItem, Item $newHeldItem, array $extraReturnedItems) : void{
|
||||
$heldItemChanged = false;
|
||||
if($this->hasFiniteResources()){
|
||||
if(!$newHeldItem->equalsExact($oldHeldItem) && $oldHeldItem->equalsExact($this->inventory->getItemInHand())){
|
||||
|
||||
if(!$newHeldItem->equalsExact($oldHeldItem) && $oldHeldItem->equalsExact($this->inventory->getItemInHand())){
|
||||
//determine if the item was changed in some meaningful way, or just damaged/changed count
|
||||
//if it was really changed we always need to set it, whether we have finite resources or not
|
||||
$newReplica = clone $oldHeldItem;
|
||||
$newReplica->setCount($newHeldItem->getCount());
|
||||
if($newReplica instanceof Durable && $newHeldItem instanceof Durable){
|
||||
$newReplica->setDamage($newHeldItem->getDamage());
|
||||
}
|
||||
$damagedOrDeducted = $newReplica->equalsExact($newHeldItem);
|
||||
|
||||
if(!$damagedOrDeducted || $this->hasFiniteResources()){
|
||||
if($newHeldItem instanceof Durable && $newHeldItem->isBroken()){
|
||||
$this->broadcastSound(new ItemBreakSound());
|
||||
}
|
||||
$this->inventory->setItemInHand($newHeldItem);
|
||||
$heldItemChanged = true;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
|
||||
if(!$heldItemChanged){
|
||||
$newHeldItem = $oldHeldItem;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user