Rough OffHand implementation

this doesn't do stuff like taking arrows from offhand yet.
This commit is contained in:
Dylan K. Taylor
2021-05-05 14:46:51 +01:00
parent e8cb49f7ae
commit 652de2632a
9 changed files with 101 additions and 11 deletions

View File

@ -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());

View File

@ -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();

View File

@ -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{