PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
CopperTrait.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\utils;
25
37
38trait CopperTrait{
39 private CopperOxidation $oxidation = CopperOxidation::NONE;
40 private bool $waxed = false;
41
42 public function describeBlockItemState(RuntimeDataDescriber $w) : void{
43 $w->enum($this->oxidation);
44 $w->bool($this->waxed);
45 }
46
47 public function getOxidation() : CopperOxidation{ return $this->oxidation; }
48
50 public function setOxidation(CopperOxidation $oxidation) : self{
51 $this->oxidation = $oxidation;
52 return $this;
53 }
54
55 public function isWaxed() : bool{ return $this->waxed; }
56
58 public function setWaxed(bool $waxed) : self{
59 $this->waxed = $waxed;
60 return $this;
61 }
62
68 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
69 if(!$this->waxed && $item->getTypeId() === ItemTypeIds::HONEYCOMB){
70 $this->waxed = true;
71 $this->position->getWorld()->setBlock($this->position, $this);
72 //TODO: orange particles are supposed to appear when applying wax
73 $this->position->getWorld()->addSound($this->position, new CopperWaxApplySound());
74 $item->pop();
75 return true;
76 }
77
78 if($item instanceof Axe){
79 if($this->waxed){
80 $this->waxed = false;
81 $this->position->getWorld()->setBlock($this->position, $this);
82 //TODO: white particles are supposed to appear when removing wax
83 $this->position->getWorld()->addSound($this->position, new CopperWaxRemoveSound());
84 $item->applyDamage(1);
85 return true;
86 }
87
88 $previousOxidation = $this->oxidation->getPrevious();
89 if($previousOxidation !== null){
90 $this->oxidation = $previousOxidation;
91 $this->position->getWorld()->setBlock($this->position, $this);
92 //TODO: turquoise particles are supposed to appear when removing oxidation
93 $this->position->getWorld()->addSound($this->position, new ScrapeSound());
94 $item->applyDamage(1);
95 return true;
96 }
97 }
98
99 return false;
100 }
101}