mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Player: fixed block-picking logic
this now matches vanilla (with some minor intentional differences) and works in survival.
This commit is contained in:
parent
f84a1729c6
commit
60225a378f
@ -2130,14 +2130,28 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ev = new PlayerBlockPickEvent($this, $block, $item);
|
$ev = new PlayerBlockPickEvent($this, $block, $item);
|
||||||
if(!$this->isCreative(true)){
|
|
||||||
$this->server->getLogger()->debug("Got block-pick request from " . $this->getName() . " when not in creative mode (gamemode " . $this->getGamemode() . ")");
|
|
||||||
$ev->setCancelled();
|
|
||||||
}
|
|
||||||
|
|
||||||
$ev->call();
|
$ev->call();
|
||||||
|
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->inventory->setItemInHand($item);
|
$existing = $this->inventory->first($item);
|
||||||
|
if($existing !== -1){
|
||||||
|
if($existing < $this->inventory->getHotbarSize()){
|
||||||
|
$this->inventory->setHeldItemIndex($existing);
|
||||||
|
}else{
|
||||||
|
$this->inventory->swap($this->inventory->getHeldItemIndex(), $existing);
|
||||||
|
}
|
||||||
|
}elseif($this->isCreative(true)){ //TODO: plugins won't know this isn't going to execute
|
||||||
|
$firstEmpty = $this->inventory->firstEmpty();
|
||||||
|
if($firstEmpty === -1){ //full inventory
|
||||||
|
$this->inventory->setItemInHand($item);
|
||||||
|
}elseif($firstEmpty < $this->inventory->getHotbarSize()){
|
||||||
|
$this->inventory->setItem($firstEmpty, $item);
|
||||||
|
$this->inventory->setHeldItemIndex($firstEmpty);
|
||||||
|
}else{
|
||||||
|
$this->inventory->swap($this->inventory->getHeldItemIndex(), $firstEmpty);
|
||||||
|
$this->inventory->setItemInHand($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user