mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-31 23:33:06 +00:00
Player: ensure that PlayerItemHeldEvent is called when the contents of the held slot changes
in PM3, this was done by implicitly relying on the client to send a MobEquipmentPacket selecting the same hotbar slot when the slot contents changes. In PM4, we avoid relying on this, and fire the event directly when the listener detects a held slot change. This ensures that the behaviour remains consistent regardless of what the client starts doing in the future. closes #4905
This commit is contained in:
parent
4a94cb85a2
commit
ea33a04d00
@ -313,6 +313,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$this->setNameTag($this->username);
|
$this->setNameTag($this->username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function callDummyItemHeldEvent() : void{
|
||||||
|
$slot = $this->inventory->getHeldItemIndex();
|
||||||
|
|
||||||
|
$event = new PlayerItemHeldEvent($this, $this->inventory->getItem($slot), $slot);
|
||||||
|
$event->call();
|
||||||
|
//TODO: this event is actually cancellable, but cancelling it here has no meaningful result, so we
|
||||||
|
//just ignore it. We fire this only because the content of the held slot changed, not because the
|
||||||
|
//held slot index changed. We can't prevent that from here, and nor would it be sensible to.
|
||||||
|
}
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
parent::initEntity($nbt);
|
parent::initEntity($nbt);
|
||||||
$this->addDefaultWindows();
|
$this->addDefaultWindows();
|
||||||
@ -321,10 +331,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
function(Inventory $unused, int $slot) : void{
|
function(Inventory $unused, int $slot) : void{
|
||||||
if($slot === $this->inventory->getHeldItemIndex()){
|
if($slot === $this->inventory->getHeldItemIndex()){
|
||||||
$this->setUsingItem(false);
|
$this->setUsingItem(false);
|
||||||
|
|
||||||
|
$this->callDummyItemHeldEvent();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function() : void{
|
function(Inventory $unused, array $changedSlots) : void{
|
||||||
$this->setUsingItem(false);
|
$this->setUsingItem(false);
|
||||||
|
$heldSlot = $this->inventory->getHeldItemIndex();
|
||||||
|
if(isset($changedSlots[$heldSlot])){
|
||||||
|
$this->callDummyItemHeldEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user