Skip to content
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

feat: add Crimson Nylium and Warped Nylium blocks #6481

Open
wants to merge 6 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,10 @@ private function __construct(){
public const COPPER_TRAPDOOR = 10735;
public const CHISELED_COPPER = 10736;
public const COPPER_GRATE = 10737;
public const CRIMSON_NYLIUM = 10738;
public const WARPED_NYLIUM = 10739;

public const FIRST_UNUSED_BLOCK_ID = 10738;
public const FIRST_UNUSED_BLOCK_ID = 10740;

private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

Expand Down
48 changes: 48 additions & 0 deletions src/block/GrassNylium.php
Original file line number Diff line number Diff line change
@@ -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;

use pocketmine\block\utils\BlockEventHelper;
use pocketmine\item\Item;

class GrassNylium extends Opaque{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nylium or NetherNylium would be better.


public function getDropsForCompatibleTool(Item $item) : array{
return [
VanillaBlocks::NETHERRACK()->asItem()
];
}

public function ticksRandomly() : bool{
return true;
}

public function onRandomTick() : void{
$world = $this->position->getWorld();
$lightAbove = $world->getFullLightAt((int) $this->position->x, (int) $this->position->y + 1, (int) $this->position->z);
if($lightAbove < 4 && $world->getBlockAt((int) $this->position->x, (int) $this->position->y + 1, (int) $this->position->z)->getLightFilter() >= 2){
Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use getSide(Facing::UP)

BlockEventHelper::spread($this, VanillaBlocks::NETHERRACK(), $this);
}
}
}
4 changes: 3 additions & 1 deletion src/block/NetherRoots.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ final class NetherRoots extends Flowable{
use StaticSupportTrait;

private function canBeSupportedAt(Block $block) : bool{
//TODO: nylium, moss
//TODO: moss
$supportBlock = $block->getSide(Facing::DOWN);
return
$supportBlock->hasTypeTag(BlockTypeTags::DIRT) ||
$supportBlock->hasTypeTag(BlockTypeTags::MUD) ||
$supportBlock->getTypeId() === BlockTypeIds::CRIMSON_NYLIUM ||
$supportBlock->getTypeId() === BlockTypeIds::WARPED_NYLIUM ||
Comment on lines +38 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to create a new Nylium tag for that is think

$supportBlock->getTypeId() === BlockTypeIds::SOUL_SOIL;
}
}
19 changes: 6 additions & 13 deletions src/block/RedMushroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@

namespace pocketmine\block;

use pocketmine\item\Item;
use pocketmine\block\utils\StaticSupportTrait;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;

class RedMushroom extends Flowable{
use StaticSupportTrait;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply only minimal change, this is unrelated to the PR "add Crimson Nylium".

Open an other PR if you want to change that.


public function ticksRandomly() : bool{
return true;
Expand All @@ -41,16 +39,11 @@ public function onNearbyBlockChange() : void{
}
}

public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
private function canBeSupportedAt(Block $block) : bool{
$supportBlock = $block->getSide(Facing::DOWN);
$position = $this->position;
$lightLevel = $position->getWorld()->getFullLightAt($position->x, $position->y, $position->z);
$downId = $down->getTypeId();
//TODO: nylium support
if(($lightLevel <= 12 && !$down->isTransparent()) || $downId === BlockTypeIds::MYCELIUM || $downId === BlockTypeIds::PODZOL){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}

return false;
$supportBlockId = $supportBlock->getTypeId();
return ($lightLevel <= 12 && !$supportBlock->isTransparent()) || $supportBlockId === BlockTypeIds::MYCELIUM || $supportBlockId === BlockTypeIds::WARPED_NYLIUM || $supportBlockId === BlockTypeIds::CRIMSON_NYLIUM || $supportBlockId === BlockTypeIds::PODZOL;
}
}
5 changes: 5 additions & 0 deletions src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
* @method static WoodenFence CRIMSON_FENCE()
* @method static FenceGate CRIMSON_FENCE_GATE()
* @method static Wood CRIMSON_HYPHAE()
* @method static GrassNylium CRIMSON_NYLIUM()
* @method static Planks CRIMSON_PLANKS()
* @method static WoodenPressurePlate CRIMSON_PRESSURE_PLATE()
* @method static NetherRoots CRIMSON_ROOTS()
Expand Down Expand Up @@ -766,6 +767,7 @@
* @method static WoodenFence WARPED_FENCE()
* @method static FenceGate WARPED_FENCE_GATE()
* @method static Wood WARPED_HYPHAE()
* @method static GrassNylium WARPED_NYLIUM()
* @method static Planks WARPED_PLANKS()
* @method static WoodenPressurePlate WARPED_PRESSURE_PLATE()
* @method static NetherRoots WARPED_ROOTS()
Expand Down Expand Up @@ -932,6 +934,9 @@ public function getBreakTime(Item $item) : float{
$grassBreakInfo = BreakInfo::shovel(0.6);
self::register("grass", new Grass(new BID(Ids::GRASS), "Grass", new Info($grassBreakInfo, [Tags::DIRT])));
self::register("grass_path", new GrassPath(new BID(Ids::GRASS_PATH), "Grass Path", new Info($grassBreakInfo)));
self::register("crimson_nylium", new GrassNylium(new BID(Ids::CRIMSON_NYLIUM), "Crimson Nylium", new Info(BreakInfo::pickaxe(0.4))));
self::register("warped_nylium", new GrassNylium(new BID(Ids::WARPED_NYLIUM), "Warped Nylium", new Info(BreakInfo::pickaxe(0.4))));
Comment on lines +937 to +938
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be good to store in an variable the break info


self::register("gravel", new Gravel(new BID(Ids::GRAVEL), "Gravel", new Info(BreakInfo::shovel(0.6))));

$hardenedClayBreakInfo = new Info(BreakInfo::pickaxe(1.25, ToolTier::WOOD, 21.0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ private function registerSimpleSerializers() : void{
$this->mapSimple(Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS(), Ids::CRACKED_POLISHED_BLACKSTONE_BRICKS);
$this->mapSimple(Blocks::CRACKED_STONE_BRICKS(), Ids::CRACKED_STONE_BRICKS);
$this->mapSimple(Blocks::CRAFTING_TABLE(), Ids::CRAFTING_TABLE);
$this->mapSimple(Blocks::CRIMSON_NYLIUM(), Ids::CRIMSON_NYLIUM);
$this->mapSimple(Blocks::CRIMSON_ROOTS(), Ids::CRIMSON_ROOTS);
$this->mapSimple(Blocks::CRYING_OBSIDIAN(), Ids::CRYING_OBSIDIAN);
$this->mapSimple(Blocks::DANDELION(), Ids::DANDELION);
Expand Down Expand Up @@ -1060,6 +1061,7 @@ private function registerSimpleSerializers() : void{
$this->mapSimple(Blocks::TUFF(), Ids::TUFF);
$this->mapSimple(Blocks::TUFF_BRICKS(), Ids::TUFF_BRICKS);
$this->mapSimple(Blocks::WARPED_WART_BLOCK(), Ids::WARPED_WART_BLOCK);
$this->mapSimple(Blocks::WARPED_NYLIUM(), Ids::WARPED_NYLIUM);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again here

$this->mapSimple(Blocks::WARPED_ROOTS(), Ids::WARPED_ROOTS);
$this->mapSimple(Blocks::WITHER_ROSE(), Ids::WITHER_ROSE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ private function registerSimpleDeserializers() : void{
$this->mapSimple(Ids::CRACKED_POLISHED_BLACKSTONE_BRICKS, fn() => Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS());
$this->mapSimple(Ids::CRACKED_STONE_BRICKS, fn() => Blocks::CRACKED_STONE_BRICKS());
$this->mapSimple(Ids::CRAFTING_TABLE, fn() => Blocks::CRAFTING_TABLE());
$this->mapSimple(Ids::CRIMSON_NYLIUM, fn() => Blocks::CRIMSON_NYLIUM());
$this->mapSimple(Ids::CRIMSON_ROOTS, fn() => Blocks::CRIMSON_ROOTS());
$this->mapSimple(Ids::CRYING_OBSIDIAN, fn() => Blocks::CRYING_OBSIDIAN());
$this->mapSimple(Ids::CUT_RED_SANDSTONE, fn() => Blocks::CUT_RED_SANDSTONE());
Expand Down Expand Up @@ -983,6 +984,7 @@ private function registerSimpleDeserializers() : void{
$this->mapSimple(Ids::TUFF_BRICKS, fn() => Blocks::TUFF_BRICKS());
$this->mapSimple(Ids::UNDYED_SHULKER_BOX, fn() => Blocks::SHULKER_BOX());
$this->mapSimple(Ids::WARPED_WART_BLOCK, fn() => Blocks::WARPED_WART_BLOCK());
$this->mapSimple(Ids::WARPED_NYLIUM, fn() => Blocks::WARPED_NYLIUM());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical order please

$this->mapSimple(Ids::WARPED_ROOTS, fn() => Blocks::WARPED_ROOTS());
$this->mapSimple(Ids::WATERLILY, fn() => Blocks::LILY_PAD());
$this->mapSimple(Ids::WEB, fn() => Blocks::COBWEB());
Expand Down
2 changes: 2 additions & 0 deletions src/item/StringToItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private static function registerBlocks(self $result) : void{
$result->registerBlock("crimson_fence", fn() => Blocks::CRIMSON_FENCE());
$result->registerBlock("crimson_fence_gate", fn() => Blocks::CRIMSON_FENCE_GATE());
$result->registerBlock("crimson_hyphae", fn() => Blocks::CRIMSON_HYPHAE()->setStripped(false));
$result->registerBlock("crimson_nylium", fn() => Blocks::CRIMSON_NYLIUM());
$result->registerBlock("crimson_planks", fn() => Blocks::CRIMSON_PLANKS());
$result->registerBlock("crimson_pressure_plate", fn() => Blocks::CRIMSON_PRESSURE_PLATE());
$result->registerBlock("crimson_roots", fn() => Blocks::CRIMSON_ROOTS());
Expand Down Expand Up @@ -1136,6 +1137,7 @@ private static function registerBlocks(self $result) : void{
$result->registerBlock("warped_fence", fn() => Blocks::WARPED_FENCE());
$result->registerBlock("warped_fence_gate", fn() => Blocks::WARPED_FENCE_GATE());
$result->registerBlock("warped_hyphae", fn() => Blocks::WARPED_HYPHAE()->setStripped(false));
$result->registerBlock("warped_nylium", fn() => Blocks::WARPED_NYLIUM());
$result->registerBlock("warped_planks", fn() => Blocks::WARPED_PLANKS());
$result->registerBlock("warped_pressure_plate", fn() => Blocks::WARPED_PRESSURE_PLATE());
$result->registerBlock("warped_roots", fn() => Blocks::WARPED_ROOTS());
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/block/block_factory_consistency_check.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"CRIMSON_FENCE": 1,
"CRIMSON_FENCE_GATE": 16,
"CRIMSON_HYPHAE": 6,
"CRIMSON_NYLIUM": 1,
"CRIMSON_PLANKS": 1,
"CRIMSON_PRESSURE_PLATE": 2,
"CRIMSON_ROOTS": 1,
Expand Down Expand Up @@ -690,6 +691,7 @@
"WARPED_FENCE": 1,
"WARPED_FENCE_GATE": 16,
"WARPED_HYPHAE": 6,
"WARPED_NYLIUM": 1,
"WARPED_PLANKS": 1,
"WARPED_PRESSURE_PLATE": 2,
"WARPED_ROOTS": 1,
Expand Down