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