From 4f8ec638c12d6a51eabeb2554d71d73448821d35 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Tue, 21 Feb 2023 22:58:54 +0300 Subject: [PATCH] Another blocks --- src/constants/BlockIDs.php | 9 +- src/material/Block.php | 9 ++ src/material/block/plant/CyanFlowerBlock.php | 14 +--- src/material/block/solid/Leaves2.php | 86 ++++++++++++++++++++ src/material/block/solid/LeavesBlock.php | 21 +++-- src/material/block/solid/Log2.php | 34 ++++++++ src/material/block/solid/StoneBlock.php | 1 + 7 files changed, 149 insertions(+), 25 deletions(-) create mode 100644 src/material/block/solid/Leaves2.php create mode 100644 src/material/block/solid/Log2.php diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php index 7307c6ee..d0ccd5c4 100755 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -226,8 +226,12 @@ define("WOODEN_SLABS", 158); define("STAINED_CLAY", 159); //ANOTHER STAINED CLAY -//LEAVES2 -//LOG2 +define("LEAVES2", 161); +define("ACACIA_LEAVES", 161); +define("DARK_OAK_LEAVES", "161:1"); +define("LOG2", 162); +define("ACACIA_WOOD", 162); +define("DARK_OAK_WOOD", "162:1"); define("ACACIA_WOOD_STAIRS", 163); define("DARK_OAK_WOOD_STAIRS", 164); @@ -235,6 +239,7 @@ define("HAY_BALE", 170); define("CARPET", 171); //ANOTHER CARPET //DOUBLE FLOWERS +define("HARDENED_CLAY", 172); define("COAL_BLOCK", 173); define("PODZOL", 243); diff --git a/src/material/Block.php b/src/material/Block.php index 581899fb..0b8016fa 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -132,6 +132,15 @@ abstract class Block extends Position{ INFO_UPDATE => "InfoUpdateBlock", INFO_UPDATE2 => "InfoUpdate2Block", RESERVED6 => "Reserved6Block", + + ACACIA_WOOD_STAIRS => "AcaciaWoodStairsBlock", + DARK_OAK_WOOD_STAIRS => "DarkOakWoodStairsBlock", + EMERALD_ORE => "EmeraldOreBlock", + EMERALD_BLOCK => "EmeraldBlock", + END_STONE => "EndStoneBlock", + HARDENED_CLAY => "HardenedClayBlock", + LOG2 => "Log2Block", + LEAVES2 => "Leaves2Block", ); protected $id; protected $meta; diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index ba490144..05ea6f6e 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -1,18 +1,8 @@ hardness = 0; $names = array( 0 => "Poppy", diff --git a/src/material/block/solid/Leaves2.php b/src/material/block/solid/Leaves2.php new file mode 100644 index 00000000..abf82569 --- /dev/null +++ b/src/material/block/solid/Leaves2.php @@ -0,0 +1,86 @@ + "Acacia Leaves", + 1 => "Dark Oak Leaves", + ); + $this->name = $names[$this->meta & 0x02]; + $this->hardness = 1; + } + + private function createIndex($x, $y, $z){ + return $index = $x.".".$y.".".$z; + } + + private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine + $index = $this->createIndex($pos->x, $pos->y, $pos->z); + if(isset($visited[$index])){ + return false; + } + $visited[$index] = true; + + $block = $this->level->getBlock($pos); + if($block instanceof WoodBlock or $block instanceof Log2Block){ //type doesn't matter + return true; + } + + if($block->getId() === $this->getId() && $distance <= 4){ + foreach(range(2, 5) as $side){ + if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess? + return true; + } + } + } + return false; + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if(($this->meta & 0b00001100) === 0){ + $this->meta |= 0x08; + $this->level->setBlock($this, $this, false, false, true); + return BLOCK_UPDATE_RANDOM; + } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(($this->meta & 0b00001100) === 0x08){ + $this->meta &= 0x02; + $visited = array(); + $check = 0; + if($this->findLog($this, $visited, 0) !== true){ + $this->level->setBlock($this, new AirBlock(), false, false, true); + if(mt_rand(1, 20) === 1){ //Saplings + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta + 2 & 0x05, 1)); + } + if(($this->meta & 0x02) === 1 and mt_rand(1, 200) === 1){ //Apples + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1)); + } + return BLOCK_UPDATE_NORMAL; + } + } + } + return false; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $this->meta |= 0x04; + $this->level->setBlock($this, $this, true, false, true); + } + + public function getDrops(Item $item, Player $player){ + $drops = array(); + if($item->isShears()){ + $drops[] = array(LEAVES2, $this->meta & 0x03, 1); + }else{ + if(mt_rand(1, 20) === 1){ //Saplings + $drops[] = array(SAPLING, $this->meta + 2 & 0x05, 1); + } + if(($this->meta & 0x03) === 1 and mt_rand(1, 100) === 1){ //Apples + $drops[] = array(APPLE, 0, 1); + } + } + return $drops; + } +} \ No newline at end of file diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index 9b724de8..6bbe485e 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -1,23 +1,22 @@ "Oak Leaves", - LeavesBlock::SPRUCE => "Spruce Leaves", - LeavesBlock::BIRCH => "Birch Leaves", - 3 => "", + WoodBlock::OAK => "Oak Leaves", + WoodBlock::SPRUCE => "Spruce Leaves", + WoodBlock::BIRCH => "Birch Leaves", + WoodBlock::JUNGLE => "Jungle Leaves", ); $this->name = $names[$this->meta & 0x03]; $this->hardness = 1; } + private function createIndex($x, $y, $z){ return $index = $x.".".$y.".".$z; } + private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine $index = $this->createIndex($pos->x, $pos->y, $pos->z); if(isset($visited[$index])){ @@ -31,7 +30,7 @@ class LeavesBlock extends TransparentBlock{ } if($block->getId() === $this->getId() && $distance <= 4){ - foreach(array(2,3,4,5) as $side){ + foreach(range(2, 5) as $side){ if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess? return true; } @@ -54,10 +53,10 @@ class LeavesBlock extends TransparentBlock{ $check = 0; if($this->findLog($this, $visited, 0) !== true){ $this->level->setBlock($this, new AirBlock(), false, false, true); - if(mt_rand(1,20) === 1){ //Saplings + if(mt_rand(1, 20) === 1){ //Saplings ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1)); } - if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples + if(($this->meta & 0x03) === WoodBlock::OAK and mt_rand(1, 200) === 1){ //Apples ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1)); } return BLOCK_UPDATE_NORMAL; @@ -80,7 +79,7 @@ class LeavesBlock extends TransparentBlock{ if(mt_rand(1,20) === 1){ //Saplings $drops[] = array(SAPLING, $this->meta & 0x03, 1); } - if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,100) === 1){ //Apples + if(($this->meta & 0x03) === WoodBlock::OAK and mt_rand(1,100) === 1){ //Apples $drops[] = array(APPLE, 0, 1); } } diff --git a/src/material/block/solid/Log2.php b/src/material/block/solid/Log2.php new file mode 100644 index 00000000..253eb600 --- /dev/null +++ b/src/material/block/solid/Log2.php @@ -0,0 +1,34 @@ + "Acacia Log", + 1 => "Dark Oak Log", + ); + $this->name = $names[$this->meta & 0x02]; + $this->hardness = 10; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $faces = array( + 0 => 0, + 1 => 0, + 2 => 0b1000, + 3 => 0b1000, + 4 => 0b0100, + 5 => 0b0100, + ); + + $this->meta = ($this->meta & 0x02) | $faces[$face]; + $this->level->setBlock($block, $this, true, false, true); + return true; + } + + public function getDrops(Item $item, Player $player){ + return array( + array($this->id, $this->meta & 0x02, 1), + ); + } +} \ No newline at end of file diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index 7d4ede1b..9bc89c2b 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -4,6 +4,7 @@ class StoneBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(STONE, $meta, "Stone"); $names = array( + 0 => "Stone", 1 => "Granite", 2 => "Polished Granite", 3 => "Diorite",