PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
Cake.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
33
34class Cake extends BaseCake{
35 public const MAX_BITES = 6;
36
37 protected int $bites = 0;
38
39 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
40 $w->boundedIntAuto(0, self::MAX_BITES, $this->bites);
41 }
42
46 protected function recalculateCollisionBoxes() : array{
47 return [
48 AxisAlignedBB::one()
49 ->contract(1 / 16, 0, 1 / 16)
50 ->trim(Facing::UP, 0.5)
51 ->trim(Facing::WEST, $this->bites / 8)
52 ];
53 }
54
55 public function getBites() : int{ return $this->bites; }
56
58 public function setBites(int $bites) : self{
59 if($bites < 0 || $bites > self::MAX_BITES){
60 throw new \InvalidArgumentException("Bites must be in range 0 ... " . self::MAX_BITES);
61 }
62 $this->bites = $bites;
63 return $this;
64 }
65
66 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
67 if($this->bites === 0 && $item instanceof ItemBlock){
68 $block = $item->getBlock();
69 $resultBlock = null;
70 if($block->getTypeId() === BlockTypeIds::CANDLE){
71 $resultBlock = VanillaBlocks::CAKE_WITH_CANDLE();
72 }elseif($block instanceof DyedCandle){
73 $resultBlock = VanillaBlocks::CAKE_WITH_DYED_CANDLE()->setColor($block->getColor());
74 }
75
76 if($resultBlock !== null){
77 $this->position->getWorld()->setBlock($this->position, $resultBlock);
78 $item->pop();
79 return true;
80 }
81 }
82
83 return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
84 }
85
86 public function getDropsForCompatibleTool(Item $item) : array{
87 return [];
88 }
89
90 public function getResidue() : Block{
91 $clone = clone $this;
92 $clone->bites++;
93 if($clone->bites > self::MAX_BITES){
94 $clone = VanillaBlocks::AIR();
95 }
96 return $clone;
97 }
98}
getDropsForCompatibleTool(Item $item)
Definition: Cake.php:86
recalculateCollisionBoxes()
Definition: Cake.php:46
setBites(int $bites)
Definition: Cake.php:58
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: Cake.php:66
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: Cake.php:39
getBlock(?int $clickedFace=null)
Definition: Item.php:491
pop(int $count=1)
Definition: Item.php:430