From 19332d0ec5e8862c635c6458b7285f609da35bfb Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 17 Aug 2023 23:23:19 +0300 Subject: [PATCH] i hate php --- src/material/block/solid/LitPumpkinBlock.php | 30 ++++++++++++++------ src/material/block/solid/PumpkinBlock.php | 5 ++-- src/world/Level.php | 9 ++++++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/material/block/solid/LitPumpkinBlock.php b/src/material/block/solid/LitPumpkinBlock.php index 870e87bc..6b31f644 100644 --- a/src/material/block/solid/LitPumpkinBlock.php +++ b/src/material/block/solid/LitPumpkinBlock.php @@ -1,6 +1,15 @@ 1, + 1 => 2, + 2 => 3, + 3 => 0, + ]; + + public function __construct($meta = 0){ parent::__construct(LIT_PUMPKIN, $meta, "Jack o'Lantern"); $this->hardness = 5; @@ -11,14 +20,17 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{ } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( - 0 => 1, - 1 => 2, - 2 => 3, - 3 => 0, - ); - $this->meta = $faces[$player->entity->getDirection()]; - $this->level->setBlock($block, $this, true, false, true); - return true; + $id = $this->level->level->getBlockID($this->x, $this->y, $this->z); + if(($id == 0 || $id == SNOW_LAYER) && $this->level->isTopSolidBlocking($this->x, $this->y - 1, $this->z)){ + $this->meta = self::$faces[$player->entity->getDirection()]; + $this->level->setBlock($block, $this, true, false, true); + return true; + } } + + public function getDrops(Item $item, Player $player){ + return [JACK_O_LANTERN, 0]; + } + + } \ No newline at end of file diff --git a/src/material/block/solid/PumpkinBlock.php b/src/material/block/solid/PumpkinBlock.php index d837ac14..e531f79e 100644 --- a/src/material/block/solid/PumpkinBlock.php +++ b/src/material/block/solid/PumpkinBlock.php @@ -5,7 +5,8 @@ class PumpkinBlock extends SolidBlock{ parent::__construct(PUMPKIN, $meta, "Pumpkin"); $this->hardness = 5; } - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $faces = array( 0 => 1, 1 => 2, @@ -15,6 +16,6 @@ class PumpkinBlock extends SolidBlock{ $this->meta = $faces[$player->entity->getDirection()]; $this->level->setBlock($block, $this, true, false, true); return true; - } + } } \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 2235d30f..9238fa46 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -60,6 +60,15 @@ class Level{ $this->__destruct(); } + public function isTopSolidBlocking($x, $y, $z){ + $idmeta = $this->level->getBlock($x, $y, $z); + $id = $idmeta[0]; + $meta = $idmeta[1]; + if($id == 0) return false; + if(StaticBlock::getIsTransparent($id)) return false; + + return true; + } /** * @param AxisAlignedBB $aABB