-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement Moss blocks #6885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Azvyl
wants to merge
26
commits into
pmmp:minor-next
Choose a base branch
from
Azvyl:moss-blocks
base: minor-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement Moss blocks #6885
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0c8567e
WIP
Azvyl c493bd2
Temporary
Azvyl dca9404
Vegetation growth logic for Moss Block
Azvyl d30930f
Moss carpet...
Azvyl bee5258
Merge branch 'refs/heads/minor-next' into moss-blocks
Azvyl 90dab53
Update MossyCarpet
Azvyl 224ad2e
Update MossyCarpet
Azvyl f5b1d45
Update MossyCarpet
Azvyl 1a6c836
MnnN
Azvyl 8fefa3f
Run update-codegen and remove moss todos
Azvyl 7a805bd
Code cleanup
Azvyl 587af93
Fix bonemeal
Azvyl 2ef7f1c
Apply requested changes
Azvyl 9b0fc3d
PaleMossBlock
Azvyl 25d7727
PaleMossCarpetVine
Azvyl 0811555
Fix placement logic and runtime data
Azvyl 0701170
Update block factory consistency chek
Azvyl 21545a3
Resolve requested change and Fix horizontal radius of PaleMossBlock
Azvyl 8f1d985
...
Azvyl 0b35f6d
Merge branch 'minor-next' into moss-blocks
Azvyl 23d3347
PaleMossVine
Azvyl d69f7e4
Refactor moss-related classes
Azvyl 2658994
Change visibility of isCarpetPart method
Azvyl ddcd55b
Merge branch 'minor-next' into moss-blocks
dktapps d161878
Merge branch 'minor-next' into moss-blocks
Azvyl 40c80c5
Azalea and Flowering Azalea block placements and fix code gen check
Azvyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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{ | ||
|
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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
dktapps marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.