Coarse is now a state of Dirt, instead of a separate block

This commit is contained in:
Dylan K. Taylor
2021-05-21 21:36:49 +01:00
parent df260034cd
commit 24405b63c1
7 changed files with 31 additions and 54 deletions

View File

@ -31,10 +31,36 @@ use pocketmine\player\Player;
class Dirt extends Opaque{
protected bool $coarse = false;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->coarse = ($stateMeta & BlockLegacyMetadata::DIRT_FLAG_COARSE) !== 0;
}
protected function writeStateToMeta() : int{
return $this->coarse ? BlockLegacyMetadata::DIRT_FLAG_COARSE : 0;
}
public function getStateBitmask() : int{
return 0b1;
}
public function getNonPersistentStateBitmask() : int{
return 0;
}
public function isCoarse() : bool{ return $this->coarse; }
/** @return $this */
public function setCoarse(bool $coarse) : self{
$this->coarse = $coarse;
return $this;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND());
$this->pos->getWorld()->setBlock($this->pos, $this->coarse ? VanillaBlocks::DIRT() : VanillaBlocks::FARMLAND());
return true;
}