mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Added rooted dirt
This commit is contained in:
parent
bedf79e2cd
commit
a7313ed9d9
@ -26,6 +26,7 @@ namespace pocketmine\build\generate_runtime_enum_serializers;
|
||||
use pocketmine\block\utils\BellAttachmentType;
|
||||
use pocketmine\block\utils\CopperOxidation;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\LeverFacing;
|
||||
use pocketmine\block\utils\MushroomBlockType;
|
||||
@ -158,6 +159,7 @@ $enumsUsed = [
|
||||
BellAttachmentType::getAll(),
|
||||
CopperOxidation::getAll(),
|
||||
CoralType::getAll(),
|
||||
DirtType::getAll(),
|
||||
DyeColor::getAll(),
|
||||
LeverFacing::getAll(),
|
||||
MushroomBlockType::getAll(),
|
||||
|
@ -23,8 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\item\Fertilizer;
|
||||
use pocketmine\item\Hoe;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Facing;
|
||||
@ -33,32 +35,50 @@ use pocketmine\player\Player;
|
||||
use pocketmine\world\sound\ItemUseOnBlockSound;
|
||||
|
||||
class Dirt extends Opaque{
|
||||
protected bool $coarse = false;
|
||||
protected DirtType $dirtType;
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->coarse);
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->dirtType = DirtType::NORMAL();
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function isCoarse() : bool{ return $this->coarse; }
|
||||
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 setCoarse(bool $coarse) : self{
|
||||
$this->coarse = $coarse;
|
||||
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->coarse ? VanillaBlocks::DIRT() : VanillaBlocks::FARMLAND();
|
||||
$world = $this->position->getWorld();
|
||||
$world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock));
|
||||
$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
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\event\block\BlockSpreadEvent;
|
||||
use pocketmine\item\Fertilizer;
|
||||
use pocketmine\item\Hoe;
|
||||
@ -72,7 +73,7 @@ class Grass extends Opaque{
|
||||
$b = $world->getBlockAt($x, $y, $z);
|
||||
if(
|
||||
!($b instanceof Dirt) ||
|
||||
$b->isCoarse() ||
|
||||
!$b->getDirtType()->equals(DirtType::NORMAL()) ||
|
||||
$world->getFullLightAt($x, $y + 1, $z) < 4 ||
|
||||
$world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
|
||||
){
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\event\block\BlockSpreadEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Facing;
|
||||
@ -51,7 +52,7 @@ class Mycelium extends Opaque{
|
||||
$z = mt_rand($this->position->z - 1, $this->position->z + 1);
|
||||
$world = $this->position->getWorld();
|
||||
$block = $world->getBlockAt($x, $y, $z);
|
||||
if($block instanceof Dirt && !$block->isCoarse()){
|
||||
if($block instanceof Dirt && $block->getDirtType()->equals(DirtType::NORMAL())){
|
||||
if($block->getSide(Facing::UP) instanceof Transparent){
|
||||
$ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM());
|
||||
$ev->call();
|
||||
|
48
src/block/utils/DirtType.php
Normal file
48
src/block/utils/DirtType.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
* This must be regenerated whenever registry members are added, removed or changed.
|
||||
* @see build/generate-registry-annotations.php
|
||||
* @generate-registry-docblock
|
||||
*
|
||||
* @method static DirtType COARSE()
|
||||
* @method static DirtType NORMAL()
|
||||
* @method static DirtType ROOTED()
|
||||
*/
|
||||
final class DirtType{
|
||||
use EnumTrait;
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("normal"),
|
||||
new self("coarse"),
|
||||
new self("rooted")
|
||||
);
|
||||
}
|
||||
}
|
@ -132,6 +132,7 @@ use pocketmine\block\TripwireHook;
|
||||
use pocketmine\block\UnderwaterTorch;
|
||||
use pocketmine\block\utils\BrewingStandSlot;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\LeverFacing;
|
||||
use pocketmine\block\VanillaBlocks as Blocks;
|
||||
@ -886,8 +887,16 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
|
||||
$this->mapStairs(Blocks::DIORITE_STAIRS(), Ids::DIORITE_STAIRS);
|
||||
$this->map(Blocks::DIORITE_WALL(), fn(Wall $block) => Helper::encodeLegacyWall($block, StringValues::WALL_BLOCK_TYPE_DIORITE));
|
||||
$this->map(Blocks::DIRT(), function(Dirt $block) : Writer{
|
||||
$dirtType = $block->getDirtType();
|
||||
if($dirtType->equals(DirtType::ROOTED())){
|
||||
return new Writer(Ids::DIRT_WITH_ROOTS);
|
||||
}
|
||||
return Writer::create(Ids::DIRT)
|
||||
->writeString(StateNames::DIRT_TYPE, $block->isCoarse() ? StringValues::DIRT_TYPE_COARSE : StringValues::DIRT_TYPE_NORMAL);
|
||||
->writeString(StateNames::DIRT_TYPE, match($dirtType){
|
||||
DirtType::COARSE() => StringValues::DIRT_TYPE_COARSE,
|
||||
DirtType::NORMAL() => StringValues::DIRT_TYPE_NORMAL,
|
||||
default => throw new AssumptionFailedError("Unhandled dirt type " . $dirtType->name())
|
||||
});
|
||||
});
|
||||
$this->map(Blocks::DOUBLE_TALLGRASS(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_GRASS, Writer::create(Ids::DOUBLE_PLANT)));
|
||||
$this->map(Blocks::DYED_SHULKER_BOX(), function(DyedShulkerBox $block) : Writer{
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\block\SweetBerryBush;
|
||||
use pocketmine\block\utils\BrewingStandSlot;
|
||||
use pocketmine\block\utils\CopperOxidation;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\LeverFacing;
|
||||
use pocketmine\block\utils\SlabType;
|
||||
@ -641,12 +642,13 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
|
||||
$this->mapStairs(Ids::DIORITE_STAIRS, fn() => Blocks::DIORITE_STAIRS());
|
||||
$this->map(Ids::DIRT, function(Reader $in) : Block{
|
||||
return Blocks::DIRT()
|
||||
->setCoarse(match($value = $in->readString(StateNames::DIRT_TYPE)){
|
||||
StringValues::DIRT_TYPE_NORMAL => false,
|
||||
StringValues::DIRT_TYPE_COARSE => true,
|
||||
->setDirtType(match($value = $in->readString(StateNames::DIRT_TYPE)){
|
||||
StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL(),
|
||||
StringValues::DIRT_TYPE_COARSE => DirtType::COARSE(),
|
||||
default => throw $in->badValueException(StateNames::DIRT_TYPE, $value),
|
||||
});
|
||||
});
|
||||
$this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED()));
|
||||
$this->map(Ids::DOUBLE_PLANT, function(Reader $in) : Block{
|
||||
return (match($type = $in->readString(StateNames::DOUBLE_PLANT_TYPE)){
|
||||
StringValues::DOUBLE_PLANT_TYPE_FERN => Blocks::LARGE_FERN(),
|
||||
|
@ -62,6 +62,15 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function dirtType(\pocketmine\block\utils\DirtType &$value) : void{
|
||||
$value = match($this->readInt(2)){
|
||||
0 => \pocketmine\block\utils\DirtType::COARSE(),
|
||||
1 => \pocketmine\block\utils\DirtType::NORMAL(),
|
||||
2 => \pocketmine\block\utils\DirtType::ROOTED(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DirtType")
|
||||
};
|
||||
}
|
||||
|
||||
public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{
|
||||
$value = match($this->readInt(4)){
|
||||
0 => \pocketmine\block\utils\DyeColor::BLACK(),
|
||||
|
@ -62,6 +62,15 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function dirtType(\pocketmine\block\utils\DirtType $value) : void{
|
||||
$this->int(2, match($value){
|
||||
\pocketmine\block\utils\DirtType::COARSE() => 0,
|
||||
\pocketmine\block\utils\DirtType::NORMAL() => 1,
|
||||
\pocketmine\block\utils\DirtType::ROOTED() => 2,
|
||||
default => throw new \pocketmine\utils\AssumptionFailedError("All DirtType cases should be covered")
|
||||
});
|
||||
}
|
||||
|
||||
public function dyeColor(\pocketmine\block\utils\DyeColor $value) : void{
|
||||
$this->int(4, match($value){
|
||||
\pocketmine\block\utils\DyeColor::BLACK() => 0,
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\Light;
|
||||
use pocketmine\block\utils\CopperOxidation;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DirtType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\utils\SlabType;
|
||||
@ -214,7 +215,7 @@ final class StringToItemParser extends StringToTParser{
|
||||
$result->registerBlock("clay_block", fn() => Blocks::CLAY());
|
||||
$result->registerBlock("coal_block", fn() => Blocks::COAL());
|
||||
$result->registerBlock("coal_ore", fn() => Blocks::COAL_ORE());
|
||||
$result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setCoarse(true));
|
||||
$result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::COARSE()));
|
||||
$result->registerBlock("cobble", fn() => Blocks::COBBLESTONE());
|
||||
$result->registerBlock("cobble_stairs", fn() => Blocks::COBBLESTONE_STAIRS());
|
||||
$result->registerBlock("cobble_wall", fn() => Blocks::COBBLESTONE_WALL());
|
||||
@ -329,7 +330,8 @@ final class StringToItemParser extends StringToTParser{
|
||||
$result->registerBlock("diorite_slab", fn() => Blocks::DIORITE_SLAB());
|
||||
$result->registerBlock("diorite_stairs", fn() => Blocks::DIORITE_STAIRS());
|
||||
$result->registerBlock("diorite_wall", fn() => Blocks::DIORITE_WALL());
|
||||
$result->registerBlock("dirt", fn() => Blocks::DIRT());
|
||||
$result->registerBlock("dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::NORMAL()));
|
||||
$result->registerBlock("dirt_with_roots", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED()));
|
||||
$result->registerBlock("door_block", fn() => Blocks::OAK_DOOR());
|
||||
$result->registerBlock("double_plant", fn() => Blocks::SUNFLOWER());
|
||||
$result->registerBlock("double_red_sandstone_slab", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE()));
|
||||
@ -914,6 +916,7 @@ final class StringToItemParser extends StringToTParser{
|
||||
$result->registerBlock("repeater", fn() => Blocks::REDSTONE_REPEATER());
|
||||
$result->registerBlock("repeater_block", fn() => Blocks::REDSTONE_REPEATER());
|
||||
$result->registerBlock("reserved6", fn() => Blocks::RESERVED6());
|
||||
$result->registerBlock("rooted_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED()));
|
||||
$result->registerBlock("rose", fn() => Blocks::POPPY());
|
||||
$result->registerBlock("rose_bush", fn() => Blocks::ROSE_BUSH());
|
||||
$result->registerBlock("sand", fn() => Blocks::SAND());
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user