PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
Dirt.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
26use pocketmine\block\utils\DirtType;
39
40class Dirt extends Opaque{
41 protected DirtType $dirtType = DirtType::NORMAL;
42
43 public function describeBlockItemState(RuntimeDataDescriber $w) : void{
44 $w->enum($this->dirtType);
45 }
46
47 public function getDirtType() : DirtType{ return $this->dirtType; }
48
50 public function setDirtType(DirtType $dirtType) : self{
51 $this->dirtType = $dirtType;
52 return $this;
53 }
54
55 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
56 $world = $this->position->getWorld();
57 if($face !== Facing::DOWN && $item instanceof Hoe){
58 $up = $this->getSide(Facing::UP);
59 if($up->getTypeId() !== BlockTypeIds::AIR){
60 return true;
61 }
62
63 $item->applyDamage(1);
64
65 $newBlock = $this->dirtType === DirtType::NORMAL ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT();
66 $center = $this->position->add(0.5, 0.5, 0.5);
67 $world->addSound($center, new ItemUseOnBlockSound($newBlock));
68 $world->setBlock($this->position, $newBlock);
69 if($this->dirtType === DirtType::ROOTED){
70 $world->dropItem($center, VanillaBlocks::HANGING_ROOTS()->asItem());
71 }
72
73 return true;
74 }elseif($this->dirtType === DirtType::ROOTED && $item instanceof Fertilizer){
75 $down = $this->getSide(Facing::DOWN);
76 if($down->getTypeId() !== BlockTypeIds::AIR){
77 return true;
78 }
79
80 $item->pop();
81 $world->setBlock($down->position, VanillaBlocks::HANGING_ROOTS());
82 //TODO: bonemeal particles, growth sounds
83 }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType() === PotionType::WATER){
84 $item->pop();
85 $world->setBlock($this->position, VanillaBlocks::MUD());
86 $world->addSound($this->position, new WaterSplashSound(0.5));
87 return true;
88 }
89
90 return false;
91 }
92}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Dirt.php:55
describeBlockItemState(RuntimeDataDescriber $w)
Definition Dirt.php:43
setDirtType(DirtType $dirtType)
Definition Dirt.php:50
pop(int $count=1)
Definition Item.php:430