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