From ce25cfbbc0586ed3a2d4f3d817e29848a75376b1 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 12 Jul 2022 16:45:30 +0300 Subject: [PATCH] Paintings cant be placed in air --- src/material/Block.php | 4 +- src/material/item/generic/Painting.php | 72 +++++++++++++++++--------- src/math/Vector3.php | 14 ++--- src/world/Position.php | 4 +- 4 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/material/Block.php b/src/material/Block.php index 43d47f17..38bb40e0 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -220,8 +220,8 @@ abstract class Block extends Position{ return $this->breakTime; } - public function getSide($side){ - $v = parent::getSide($side); + public function getSide($side, $step = 1){ + $v = parent::getSide($side, $step); if($this->level instanceof Level){ return $this->level->getBlock($v); } diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index a82a87db..d8c00843 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -24,6 +24,31 @@ class PaintingItem extends Item{ parent::__construct(PAINTING, 0, $count, "Painting"); $this->isActivable = true; } + private static $motives = array( + // Motive Width Height + array("Wasteland", 1, 1), + array("Wanderer", 1, 2), + array("Graham", 1, 2), + array("Pool", 2, 1), + array("Courbet", 2, 1), + array("Sunset", 2, 1), + array("Sea", 2, 1), + array("Creebet", 2, 1), + array("Match", 2, 2), + array("Bust", 2, 2), + array("Stage", 2, 2), + array("Void", 2, 2), + array("SkullAndRoses", 2, 2), + //array("Wither", 2, 2), + array("Fighters", 4, 2), + array("Skeleton", 4, 3), + array("DonkeyKong", 4, 3), + array("Pointer", 4, 4), + array("Pigscene", 4, 4), + array("Flaming Skull", 4, 4), + ); + private static $direction = array(2, 0, 1, 3); + private static $right = array(4, 5, 3, 2); public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false and $face > 1 and $block->isSolid === false){ @@ -35,36 +60,35 @@ class PaintingItem extends Item{ 5 => 2, ); - $motives = array( - // Motive Width Height + + $validMotives = array( array("Kebab", 1, 1), array("Aztec", 1, 1), array("Alban", 1, 1), array("Aztec2", 1, 1), array("Bomb", 1, 1), - array("Plant", 1, 1), - array("Wasteland", 1, 1), - array("Wanderer", 1, 2), - array("Graham", 1, 2), - array("Pool", 2, 1), - array("Courbet", 2, 1), - array("Sunset", 2, 1), - array("Sea", 2, 1), - array("Creebet", 2, 1), - array("Match", 2, 2), - array("Bust", 2, 2), - array("Stage", 2, 2), - array("Void", 2, 2), - array("SkullAndRoses", 2, 2), - //array("Wither", 2, 2), - array("Fighters", 4, 2), - array("Skeleton", 4, 3), - array("DonkeyKong", 4, 3), - array("Pointer", 4, 4), - array("Pigscene", 4, 4), - array("Flaming Skull", 4, 4), + array("Plant", 1, 1), ); - $motive = $motives[mt_rand(0, count($motives) - 1)]; + foreach(PaintingItem::$motives as $motive){ + $valid = true; + for($x = 0; $x <= $motive[1]; $x++){ + for($y = 0; $y <= $motive[2]; $y++){ + if ($target->getSide(PaintingItem::$right[$face - 2], $x)->isTransparent || $target->getSide(1, $y)->isTransparent + || $block->getSide(PaintingItem::$right[$face - 2], $x)->isSolid || $block->getSide(1, $y)->isSolid) { + $valid = false; + break; + } + } + if(!$valid){ + break; + } + } + if ($valid) { + $validMotives[] = $motive; + } + } + $motive = $validMotives[array_rand($validMotives)]; + console(json_encode($motive)); $data = array( "x" => $target->x, "y" => $target->y, diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 097424f0..7b8b8761 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -112,20 +112,20 @@ class Vector3{ return new Vector3(abs($this->x), abs($this->y), abs($this->z)); } - public function getSide($side){ + public function getSide($side, $step = 1){ switch((int) $side){ case 0: - return new Vector3($this->x, $this->y - 1, $this->z); + return new Vector3($this->x, $this->y - $step, $this->z); case 1: - return new Vector3($this->x, $this->y + 1, $this->z); + return new Vector3($this->x, $this->y + $step, $this->z); case 2: - return new Vector3($this->x, $this->y, $this->z - 1); + return new Vector3($this->x, $this->y, $this->z - $step); case 3: - return new Vector3($this->x, $this->y, $this->z + 1); + return new Vector3($this->x, $this->y, $this->z + $step); case 4: - return new Vector3($this->x - 1, $this->y, $this->z); + return new Vector3($this->x - $step, $this->y, $this->z); case 5: - return new Vector3($this->x + 1, $this->y, $this->z); + return new Vector3($this->x + $step, $this->y, $this->z); default: return $this; } diff --git a/src/world/Position.php b/src/world/Position.php index d000910e..ee28302b 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -33,8 +33,8 @@ class Position extends Vector3{ $this->level = $level; } - public function getSide($side){ - return new Position(parent::getSide($side), 0, 0, $this->level); + public function getSide($side, $step = 1){ + return new Position(parent::getSide($side, $step), 0, 0, $this->level); } public function distance($x = 0, $y = 0, $z = 0){