Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/block/BaseBigDripleaf.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ abstract class BaseBigDripleaf extends Transparent implements HorizontalFacing{
abstract protected function isHead() : bool;

private function canBeSupportedBy(Block $block, bool $head) : bool{
//TODO: Moss block
return
($block instanceof BaseBigDripleaf && $block->isHead() === $head) ||
$block->getTypeId() === BlockTypeIds::CLAY ||
Expand Down
6 changes: 5 additions & 1 deletion src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,12 @@ private function __construct(){
public const WARPED_NYLIUM = 10804;
public const INFESTED_DEEPSLATE = 10805;
public const STRUCTURE_VOID = 10806;
public const MOSS_BLOCK = 10807;
public const MOSS_CARPET = 10808;
public const PALE_MOSS_BLOCK = 10809;
public const PALE_MOSS_CARPET = 10810;

public const FIRST_UNUSED_BLOCK_ID = 10807;
public const FIRST_UNUSED_BLOCK_ID = 10811;

private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

Expand Down
1 change: 1 addition & 0 deletions src/block/BlockTypeTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ final class BlockTypeTags{
public const HANGING_SIGN = self::PREFIX . "hanging_sign";
public const NYLIUM = self::PREFIX . "nylium";
public const HUGE_FUNGUS_REPLACEABLE = self::PREFIX . "huge_fungus_replaceable";
public const MOSS_REPLACEABLE = self::PREFIX . "moss_replaceable";
}
5 changes: 3 additions & 2 deletions src/block/DeadBush.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ private function canBeSupportedAt(Block $block) : bool{
BlockTypeIds::DIRT,
BlockTypeIds::GRASS,
BlockTypeIds::HARDENED_CLAY,
BlockTypeIds::STAINED_CLAY => true,
//TODO: moss block
BlockTypeIds::STAINED_CLAY,
BlockTypeIds::MOSS_BLOCK,
BlockTypeIds::PALE_MOSS_BLOCK => true,
Comment thread
Azvyl marked this conversation as resolved.
default => false,
};
}
Expand Down
100 changes: 100 additions & 0 deletions src/block/MossBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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;

use pocketmine\block\utils\BlockEventHelper;
use pocketmine\item\Fertilizer;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use pocketmine\world\Position;
use function abs;
use function mt_rand;

class MossBlock extends Opaque{
Comment thread
Azvyl marked this conversation as resolved.
Outdated
protected const VERTICAL_RANGE = 5;

/**
* @phpstan-param \Closure(BlockTransaction, Position): void $vegetationSelector
*/
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, private readonly \Closure $vegetationSelector){
parent::__construct($idInfo, $name, $typeInfo);
}

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if(!($item instanceof Fertilizer) || $this->getSide(Facing::UP)->getTypeId() !== BlockTypeIds::AIR){
return false;
}

$item->pop();

$world = $this->position->getWorld();
$maxX = mt_rand(0, 1) === 0 ? 2 : 3;
$maxZ = mt_rand(0, 1) === 0 ? 2 : 3;
$originX = $this->position->x;
$originY = $this->position->y;
$originZ = $this->position->z;

for($dx = -$maxX; $dx <= $maxX; ++$dx){
for($dz = -$maxZ; $dz <= $maxZ; ++$dz){
if(
(abs($dx) === $maxX && abs($dz) === $maxZ) ||
((abs($dx) === $maxX || abs($dz) === $maxZ) && mt_rand(1, 100) > 75)
){
continue;
}

$x = $originX + $dx;
$z = $originZ + $dz;
$startY = $originY + 1;
$foundBlock = null;
$direction = $world->getBlockAt($x, $startY, $z)->getTypeId() === BlockTypeIds::AIR ? -1 : 1;
$limit = $direction === -1 ? $originY - self::VERTICAL_RANGE : $originY + self::VERTICAL_RANGE;

for($y = $startY; $direction === -1 ? $y >= $limit : $y <= $limit; $y += $direction){
$b = $world->getBlockAt($x, $y, $z);
if($b->getTypeId() !== BlockTypeIds::AIR && $world->getBlockAt($x, $y + 1, $z)->getTypeId() === BlockTypeIds::AIR){
$foundBlock = $b;
break;
}
}

if(
$foundBlock !== null && $foundBlock->hasTypeTag(BlockTypeTags::MOSS_REPLACEABLE) &&
($foundBlock->hasSameTypeId($this) || BlockEventHelper::spread($foundBlock, (clone $this), $this)) &&
mt_rand(1, 100) <= 60
){
$above = $foundBlock->getSide(Facing::UP);
$tx = new BlockTransaction($world);
($this->vegetationSelector)($tx, $above->getPosition());
$tx->apply();
}
}
}

return true;
}
}
40 changes: 40 additions & 0 deletions src/block/MossCarpet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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;

use pocketmine\block\utils\StaticSupportTrait;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;

class MossCarpet extends Flowable{
use StaticSupportTrait;

protected function recalculateCollisionBoxes() : array{
return [AxisAlignedBB::one()->trim(Facing::UP, 15 / 16)];
}

private function canBeSupportedAt(Block $block) : bool{
return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR;
}
}
Comment thread
dktapps marked this conversation as resolved.
1 change: 0 additions & 1 deletion src/block/NetherFungus.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __construct(
}

private function canBeSupportedAt(Block $block) : bool{
//TODO: moss
Comment thread
ShockedPlot7560 marked this conversation as resolved.
$supportBlock = $block->getSide(Facing::DOWN);
return
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
Expand Down
1 change: 0 additions & 1 deletion src/block/NetherRoots.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ final class NetherRoots extends Flowable{
use StaticSupportTrait;

private function canBeSupportedAt(Block $block) : bool{
//TODO: moss
Comment thread
ShockedPlot7560 marked this conversation as resolved.
$supportBlock = $block->getSide(Facing::DOWN);
return
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
Expand Down
1 change: 0 additions & 1 deletion src/block/NetherSprouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class NetherSprouts extends Flowable{
use StaticSupportTrait;

private function canBeSupportedAt(Block $block) : bool{
//TODO: moss
Comment thread
ShockedPlot7560 marked this conversation as resolved.
$supportBlock = $block->getSide(Facing::DOWN);
return
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
Expand Down
Loading
Loading