From 9118406d7ddbfde7f9d24180fd802f0196ed0eb9 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Tue, 28 Feb 2023 22:16:38 +0300 Subject: [PATCH] Added Vines and Mycelium blocks --- src/constants/BlockIDs.php | 2 +- src/material/Block.php | 2 ++ src/material/block/plant/CocoaBlock.php | 35 ++++++++++------------ src/material/block/plant/LilypadBlock.php | 0 src/material/block/plant/VinesBlock.php | 35 ++++++++++++++++++++++ src/material/block/solid/MyceliumBlock.php | 12 ++++---- 6 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 src/material/block/plant/LilypadBlock.php create mode 100644 src/material/block/plant/VinesBlock.php diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php index f3725b72..6a1a67a1 100755 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -182,7 +182,7 @@ define("GLASS_PANEL", 102); define("MELON_BLOCK", 103); define("PUMPKIN_STEM", 104); define("MELON_STEM", 105); - +define("VINES", 106); define("FENCE_GATE", 107); define("BRICK_STAIRS", 108); define("STONE_BRICK_STAIRS", 109); diff --git a/src/material/Block.php b/src/material/Block.php index 942d0b08..8617d822 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -146,6 +146,8 @@ abstract class Block extends Position{ RED_MUSHROOM_BLOCK => "RedMushroomSolidBlock", BROWN_MUSHROOM_BLOCK => "BrownMushroomSolidBlock", MONSTER_SPAWNER => "MonsterSpawnerBlock", + VINES => "VinesBlock", + MYCELIUM => "MyceliumBlock", ); protected $id; protected $meta; diff --git a/src/material/block/plant/CocoaBlock.php b/src/material/block/plant/CocoaBlock.php index 5e055529..2710d15a 100644 --- a/src/material/block/plant/CocoaBlock.php +++ b/src/material/block/plant/CocoaBlock.php @@ -8,15 +8,23 @@ class CocoaBlock extends FlowableBlock{ } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($target->getID() === WOOD and ($target->getMetadata() & 0x03) === 0x03){ - //$this->meta = $face; - $this->level->setBlock($block, $this, true, false, true); + if($face === 0 || $face === 1){ + return false; //fix of placing invalid ids without array + } + if($target->isTransparent === false){ + $faces = array( + 2 => 0x00, + 3 => 0x00, + 4 => 0x00, + 5 => 0x00, + ); + $this->level->setBlock($this, BlockAPI::get($this->id, $faces[$face]), true, false, true); return true; } return false; } - public function onActivate(Item $item, Player $player){ + /*public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta++; if($this->meta > 0x02){ @@ -32,20 +40,7 @@ class CocoaBlock extends FlowableBlock{ } public function onUpdate($type){ - if($type === BLOCK_UPDATE_NORMAL){ - /*$side = $this->getMetadata(); - $faces = array( //magical tranformation - 3 => 2, - 2 => 3, - 5 => 4, - 4 => 5, - ); - if($this->getSide($faces[$side]) instanceof AirBlock){ //Replace with common break method - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1)); - $this->level->setBlock($this, new AirBlock(), true, false, true); - return BLOCK_UPDATE_NORMAL; - }*/ - }elseif($type === BLOCK_UPDATE_RANDOM){ + if($type === BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x03){ ++$this->meta; @@ -57,11 +52,11 @@ class CocoaBlock extends FlowableBlock{ } } return false; - } + }*/ public function getDrops(Item $item, Player $player){ $drops = []; - if($this->meta >= 0x02){ + if($this->meta >= 0x02){ //hum? $drops[] = [DYE, 3, mt_rand(1, 4)]; }else{ $drops[] = [DYE, 3, 1]; diff --git a/src/material/block/plant/LilypadBlock.php b/src/material/block/plant/LilypadBlock.php new file mode 100644 index 00000000..e69de29b diff --git a/src/material/block/plant/VinesBlock.php b/src/material/block/plant/VinesBlock.php new file mode 100644 index 00000000..1177962b --- /dev/null +++ b/src/material/block/plant/VinesBlock.php @@ -0,0 +1,35 @@ +isSolid = false; + $this->isFullBlock = false; + $this->hardness = 2; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($face === 0 || $face === 1){ + return false; //fix of placing invalid ids without array + } + if($target->isTransparent === false){ + $faces = array( + 2 => 0x01, + 3 => 0x04, + 4 => 0x08, + 5 => 0x02, + ); + $this->level->setBlock($this, BlockAPI::get($this->id, $faces[$face]), true, false, true); + return true; + } + return false; + } + + public function getDrops(Item $item, Player $player){ + $drops = array(); + if($item->isShears()){ + $drops[] = array($this->id, 0, 1); + } + return $drops; + } +} diff --git a/src/material/block/solid/MyceliumBlock.php b/src/material/block/solid/MyceliumBlock.php index 3e714e89..77c3d633 100644 --- a/src/material/block/solid/MyceliumBlock.php +++ b/src/material/block/solid/MyceliumBlock.php @@ -7,16 +7,16 @@ class MyceliumBlock extends SolidBlock{ $this->hardness = 3; } - public function getDrops(Item $item, Player $player){ - return array( - array(DIRT, 0, 1), - ); - } - public function onUpdate($type){ if($type === BLOCK_UPDATE_RANDOM && !$this->getSide(1)->isTransparent && mt_rand(0, 2) == 1){ $this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true); } return BLOCK_UPDATE_RANDOM; } + + public function getDrops(Item $item, Player $player){ + return array( + array(DIRT, 0, 1), + ); + } } \ No newline at end of file