dirtType = DirtType::NORMAL(); parent::__construct($idInfo, $name, $typeInfo); } public function getRequiredTypeDataBits() : int{ return 2; } protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->dirtType($this->dirtType); } public function getDirtType() : DirtType{ return $this->dirtType; } /** @return $this */ public function setDirtType(DirtType $dirtType) : self{ $this->dirtType = $dirtType; return $this; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); if($face === Facing::UP && $item instanceof Hoe){ $item->applyDamage(1); $newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); $center = $this->position->add(0.5, 0.5, 0.5); $world->addSound($center, new ItemUseOnBlockSound($newBlock)); $world->setBlock($this->position, $newBlock); if($this->dirtType->equals(DirtType::ROOTED())){ $world->dropItem($center, VanillaBlocks::HANGING_ROOTS()->asItem()); } return true; }elseif($this->dirtType->equals(DirtType::ROOTED()) && $item instanceof Fertilizer){ $down = $this->getSide(Facing::DOWN); if($down->getTypeId() !== BlockTypeIds::AIR){ return true; } $item->pop(); $world->setBlock($down->position, VanillaBlocks::HANGING_ROOTS()); //TODO: bonemeal particles, growth sounds }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType()->equals(PotionType::WATER())){ $item->pop(); $world->setBlock($this->position, VanillaBlocks::MUD()); $world->addSound($this->position, new WaterSplashSound(0.5)); return true; } return false; } }