mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Rough OffHand implementation
this doesn't do stuff like taking arrows from offhand yet.
This commit is contained in:
@ -96,6 +96,7 @@ class InventoryManager{
|
||||
$this->containerOpenCallbacks->add(\Closure::fromCallable([self::class, 'createContainerOpen']));
|
||||
|
||||
$this->add(ContainerIds::INVENTORY, $this->player->getInventory());
|
||||
$this->add(ContainerIds::OFFHAND, $this->player->getOffHandInventory());
|
||||
$this->add(ContainerIds::ARMOR, $this->player->getArmorInventory());
|
||||
$this->add(ContainerIds::UI, $this->player->getCursorInventory());
|
||||
|
||||
|
@ -963,14 +963,18 @@ class NetworkSession{
|
||||
|
||||
/**
|
||||
* TODO: expand this to more than just humans
|
||||
* TODO: offhand
|
||||
*/
|
||||
public function onMobEquipmentChange(Human $mob) : void{
|
||||
public function onMobMainHandItemChange(Human $mob) : void{
|
||||
//TODO: we could send zero for slot here because remote players don't need to know which slot was selected
|
||||
$inv = $mob->getInventory();
|
||||
$this->sendDataPacket(MobEquipmentPacket::create($mob->getId(), ItemStackWrapper::legacy(TypeConverter::getInstance()->coreItemStackToNet($inv->getItemInHand())), $inv->getHeldItemIndex(), ContainerIds::INVENTORY));
|
||||
}
|
||||
|
||||
public function onMobOffHandItemChange(Human $mob) : void{
|
||||
$inv = $mob->getOffHandInventory();
|
||||
$this->sendDataPacket(MobEquipmentPacket::create($mob->getId(), ItemStackWrapper::legacy(TypeConverter::getInstance()->coreItemStackToNet($inv->getItem(0))), 0, ContainerIds::OFFHAND));
|
||||
}
|
||||
|
||||
public function onMobArmorChange(Living $mob) : void{
|
||||
$inv = $mob->getArmorInventory();
|
||||
$converter = TypeConverter::getInstance();
|
||||
|
@ -463,11 +463,17 @@ class InGamePacketHandler extends PacketHandler{
|
||||
}
|
||||
|
||||
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
|
||||
$this->session->getInvManager()->onClientSelectHotbarSlot($packet->hotbarSlot);
|
||||
if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
|
||||
$this->session->getInvManager()->syncSelectedHotbarSlot();
|
||||
if($packet->windowId === ContainerIds::OFFHAND){
|
||||
return true; //this happens when we put an item into the offhand
|
||||
}
|
||||
return true;
|
||||
if($packet->windowId === ContainerIds::INVENTORY){
|
||||
$this->session->getInvManager()->onClientSelectHotbarSlot($packet->hotbarSlot);
|
||||
if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
|
||||
$this->session->getInvManager()->syncSelectedHotbarSlot();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
|
||||
|
Reference in New Issue
Block a user