mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Added cake eating
This commit is contained in:
parent
306cc9f00c
commit
28f6a964d4
@ -260,7 +260,7 @@ class BlockAPI{
|
|||||||
return $this->cancelAction($target, $player, false);
|
return $this->cancelAction($target, $player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - 0.02) + $target->getBreakTime($item, $player)) >= microtime(true)){
|
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - 0.05) + $target->getBreakTime($item, $player)) >= microtime(true)){
|
||||||
return $this->cancelAction($target, $player, false);
|
return $this->cancelAction($target, $player, false);
|
||||||
}
|
}
|
||||||
$player->lastBreak = microtime(true);
|
$player->lastBreak = microtime(true);
|
||||||
@ -350,7 +350,7 @@ class BlockAPI{
|
|||||||
if(($player->gamemode & 0x01) === 0x00){
|
if(($player->gamemode & 0x01) === 0x00){
|
||||||
--$item->count;
|
--$item->count;
|
||||||
if($item->count <= 0){
|
if($item->count <= 0){
|
||||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0));
|
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,9 +340,11 @@ class Player{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSlot($slot, Item $item){
|
public function setSlot($slot, Item $item, $send = true){
|
||||||
$this->inventory[(int) $slot] = $item;
|
$this->inventory[(int) $slot] = $item;
|
||||||
|
if($send === true){
|
||||||
$this->sendInventorySlot((int) $slot);
|
$this->sendInventorySlot((int) $slot);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1387,7 +1389,7 @@ class Player{
|
|||||||
RAW_FISH => 2,
|
RAW_FISH => 2,
|
||||||
|
|
||||||
);
|
);
|
||||||
if(isset($items[$this->getSlot($this->slot)->getID()])){
|
if($this->entity->getHealth() < 20 and isset($items[$this->getSlot($this->slot)->getID()])){
|
||||||
if($this->removeItem($this->getSlot($this->slot)->getID(), $this->getSlot($this->slot)->getMetadata(), 1, false) === true){
|
if($this->removeItem($this->getSlot($this->slot)->getID(), $this->getSlot($this->slot)->getMetadata(), 1, false) === true){
|
||||||
$this->dataPacket(MC_ENTITY_EVENT, array(
|
$this->dataPacket(MC_ENTITY_EVENT, array(
|
||||||
"eid" => 0,
|
"eid" => 0,
|
||||||
|
@ -26,9 +26,25 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class CakeBlock extends TransparentBlock{
|
class CakeBlock extends TransparentBlock{
|
||||||
public function __construct(){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
|
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
|
||||||
$this->isFullBlock = false;
|
$this->isFullBlock = false;
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->meta = $meta & 0x07;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player){
|
||||||
|
if($player->entity->getHealth() < 20){
|
||||||
|
++$this->meta;
|
||||||
|
$player->entity->heal(3, "cake");
|
||||||
|
if($this->meta >= 0x06){
|
||||||
|
$this->level->setBlock($this, new AirBlock());
|
||||||
|
}else{
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user