Paintings cant be placed in air

This commit is contained in:
GameHerobrine 2022-07-12 16:45:30 +03:00
parent af79b29f26
commit ce25cfbbc0
4 changed files with 59 additions and 35 deletions

View file

@ -220,8 +220,8 @@ abstract class Block extends Position{
return $this->breakTime; return $this->breakTime;
} }
public function getSide($side){ public function getSide($side, $step = 1){
$v = parent::getSide($side); $v = parent::getSide($side, $step);
if($this->level instanceof Level){ if($this->level instanceof Level){
return $this->level->getBlock($v); return $this->level->getBlock($v);
} }

View file

@ -24,25 +24,8 @@ class PaintingItem extends Item{
parent::__construct(PAINTING, 0, $count, "Painting"); parent::__construct(PAINTING, 0, $count, "Painting");
$this->isActivable = true; $this->isActivable = true;
} }
private static $motives = array(
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){
$server = ServerAPI::request();
$faces = array(
2 => 1,
3 => 3,
4 => 0,
5 => 2,
);
$motives = array(
// Motive Width Height // Motive Width Height
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("Wasteland", 1, 1),
array("Wanderer", 1, 2), array("Wanderer", 1, 2),
array("Graham", 1, 2), array("Graham", 1, 2),
@ -64,7 +47,48 @@ class PaintingItem extends Item{
array("Pigscene", 4, 4), array("Pigscene", 4, 4),
array("Flaming Skull", 4, 4), array("Flaming Skull", 4, 4),
); );
$motive = $motives[mt_rand(0, count($motives) - 1)]; 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){
$server = ServerAPI::request();
$faces = array(
2 => 1,
3 => 3,
4 => 0,
5 => 2,
);
$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),
);
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( $data = array(
"x" => $target->x, "x" => $target->x,
"y" => $target->y, "y" => $target->y,

View file

@ -112,20 +112,20 @@ class Vector3{
return new Vector3(abs($this->x), abs($this->y), abs($this->z)); 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){ switch((int) $side){
case 0: case 0:
return new Vector3($this->x, $this->y - 1, $this->z); return new Vector3($this->x, $this->y - $step, $this->z);
case 1: case 1:
return new Vector3($this->x, $this->y + 1, $this->z); return new Vector3($this->x, $this->y + $step, $this->z);
case 2: case 2:
return new Vector3($this->x, $this->y, $this->z - 1); return new Vector3($this->x, $this->y, $this->z - $step);
case 3: case 3:
return new Vector3($this->x, $this->y, $this->z + 1); return new Vector3($this->x, $this->y, $this->z + $step);
case 4: case 4:
return new Vector3($this->x - 1, $this->y, $this->z); return new Vector3($this->x - $step, $this->y, $this->z);
case 5: case 5:
return new Vector3($this->x + 1, $this->y, $this->z); return new Vector3($this->x + $step, $this->y, $this->z);
default: default:
return $this; return $this;
} }

View file

@ -33,8 +33,8 @@ class Position extends Vector3{
$this->level = $level; $this->level = $level;
} }
public function getSide($side){ public function getSide($side, $step = 1){
return new Position(parent::getSide($side), 0, 0, $this->level); return new Position(parent::getSide($side, $step), 0, 0, $this->level);
} }
public function distance($x = 0, $y = 0, $z = 0){ public function distance($x = 0, $y = 0, $z = 0){