Bows can now use offhand arrows (#4356)

This commit is contained in:
Rush2929 2021-08-11 03:36:57 +09:00 committed by GitHub
parent 2cdd6e634f
commit cf77b33c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,7 +46,13 @@ class Bow extends Tool implements Releasable{
public function onReleaseUsing(Player $player) : ItemUseResult{
$arrow = VanillaItems::ARROW();
if($player->hasFiniteResources() and !$player->getInventory()->contains($arrow)){
$inventory = match(true){
$player->getOffHandInventory()->contains($arrow) => $player->getOffHandInventory(),
$player->getInventory()->contains($arrow) => $player->getInventory(),
default => null
};
if($player->hasFiniteResources() and $inventory === null){
return ItemUseResult::FAIL();
}
@ -110,7 +116,7 @@ class Bow extends Tool implements Releasable{
if($player->hasFiniteResources()){
if(!$infinity){ //TODO: tipped arrows are still consumed when Infinity is applied
$player->getInventory()->removeItem($arrow);
$inventory?->removeItem($arrow);
}
$this->applyDamage(1);
}