Improved PlayerInventory->setItemInHand() $source call, fixed Tool durability

This commit is contained in:
Shoghi Cervantes 2014-09-29 17:53:53 +02:00
parent 762c27affe
commit 1252dd65a9
2 changed files with 12 additions and 9 deletions

View File

@ -1572,7 +1572,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$item = clone $this->inventory->getItemInHand(); $item = clone $this->inventory->getItemInHand();
//TODO: Implement adventure mode checks //TODO: Implement adventure mode checks
if($this->getLevel()->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ if($this->getLevel()->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
$this->inventory->setItemInHand($item); $this->inventory->setItemInHand($item, $this);
$this->inventory->sendHeldItem($this->hasSpawned); $this->inventory->sendHeldItem($this->hasSpawned);
break; break;
} }
@ -1652,9 +1652,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($this->isSurvival()){ if($this->isSurvival()){
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); $this->inventory->removeItem(Item::get(Item::ARROW, 0, 1));
$bow->setDamage($bow->getDamage() + 1); $bow->setDamage($bow->getDamage() + 1);
$this->inventory->setItemInHand($bow); $this->inventory->setItemInHand($bow, $this);
if($bow->getDamage() >= 385){ if($bow->getDamage() >= 385){
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0), $this);
} }
} }
$arrow->spawnToAll(); $arrow->spawnToAll();
@ -1687,7 +1687,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($this->getLevel()->useBreakOn($vector, $item, $this) === true){ if($this->getLevel()->useBreakOn($vector, $item, $this) === true){
if($this->isSurvival()){ if($this->isSurvival()){
$this->inventory->setItemInHand($item); $this->inventory->setItemInHand($item, $this);
$this->inventory->sendHeldItem($this->hasSpawned); $this->inventory->sendHeldItem($this->hasSpawned);
} }
break; break;
@ -1862,7 +1862,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($item->isTool() and $this->isSurvival()){ if($item->isTool() and $this->isSurvival()){
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
}else{
$this->inventory->setItemInHand($item, $this);
} }
} }
} }
@ -1962,7 +1964,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->heal($items[$slot->getID()]); $this->heal($items[$slot->getID()]);
--$slot->count; --$slot->count;
$this->inventory->setItemInHand($slot); $this->inventory->setItemInHand($slot, $this);
if($slot->getID() === Item::MUSHROOM_STEW or $slot->getID() === Item::BEETROOT_SOUP){ if($slot->getID() === Item::MUSHROOM_STEW or $slot->getID() === Item::BEETROOT_SOUP){
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1)); $this->inventory->addItem(Item::get(Item::BOWL, 0, 1));
} }
@ -1983,7 +1985,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
break; break;
} }
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
$motion = $this->getDirectionVector()->multiply(0.4); $motion = $this->getDirectionVector()->multiply(0.4);
$this->getLevel()->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); $this->getLevel()->dropItem($this->add(0, 1.3, 0), $item, $motion, 40);

View File

@ -89,11 +89,12 @@ class PlayerInventory extends BaseInventory{
/** /**
* @param Item $item * @param Item $item
* @param $source
* *
* @return bool * @return bool
*/ */
public function setItemInHand(Item $item){ public function setItemInHand(Item $item, $source = null){
return $this->setItem($this->getHeldItemSlot(), $item); return $this->setItem($this->getHeldItemSlot(), $item, $source);
} }
public function getHeldItemSlot(){ public function getHeldItemSlot(){