From f73e7f8504e3fc181e7e87a999034cd08d3b711c Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Wed, 22 Dec 2021 18:07:37 +0300 Subject: [PATCH] Added PoweredRail --- src/constants/BlockIDs.php | 2 +- src/material/Block.php | 1 + src/material/block/nonfull/PoweredRail.php | 50 ++++++++++++++++++++++ src/recipes/CraftingRecipes.php | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/material/block/nonfull/PoweredRail.php diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php index 664254b0..0285f1ab 100644 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -53,7 +53,7 @@ define("LAPIS_BLOCK", 22); define("SANDSTONE", 24); define("BED_BLOCK", 26); - +define("POWERED_RAIL", 27); define("COBWEB", 30); define("TALL_GRASS", 31); diff --git a/src/material/Block.php b/src/material/Block.php index 07d804c7..223edc13 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -46,6 +46,7 @@ abstract class Block extends Position{ LAPIS_BLOCK => "LapisBlock", SANDSTONE => "SandstoneBlock", BED_BLOCK => "BedBlock", + POWERED_RAIL => "PoweredRailBlock", COBWEB => "CobwebBlock", TALL_GRASS => "TallGrassBlock", DEAD_BUSH => "DeadBushBlock", diff --git a/src/material/block/nonfull/PoweredRail.php b/src/material/block/nonfull/PoweredRail.php new file mode 100644 index 00000000..fbaa44eb --- /dev/null +++ b/src/material/block/nonfull/PoweredRail.php @@ -0,0 +1,50 @@ +hardness = 0.7; + $this->isFullBlock = false; + $this->isSolid = true; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); + if($down->getID() !== AIR and $down instanceof SolidBlock){ + $this->level->setBlock($block, $this, true, false, true); + return true; + } + return false; + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->getID() === AIR){ //Replace with common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); + $this->level->setBlock($this, new AirBlock(), true, false, true); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } + +} \ No newline at end of file diff --git a/src/recipes/CraftingRecipes.php b/src/recipes/CraftingRecipes.php index f06d161b..cdf33ae2 100644 --- a/src/recipes/CraftingRecipes.php +++ b/src/recipes/CraftingRecipes.php @@ -144,6 +144,7 @@ class CraftingRecipes{ "WOODEN_PLANKS:?x1,STICK:?x2=>WOODEN_SHOVEL:0x1", "WOODEN_PLANKS:?x2,STICK:?x1=>WOODEN_SWORD:0x1", "IRON_INGOT:?x6,STICK:?x1=>RAIL:0x16", + "GOLD_INGOT:?x6,STICK:?x1,REDSTONE:?x1=>POWERED_RAIL:0x6", //Food & protection "BEETROOT:?x4,BOWL:?x1=>BEETROOT_SOUP:0x1",