ported painting placement from 0.8(didnt add painting collisoion checks yet)

This commit is contained in:
GameHerobrine 2024-11-26 17:49:10 +03:00
parent 61ee4ab335
commit 96f4cb6382
3 changed files with 175 additions and 65 deletions

View file

@ -5,28 +5,34 @@ class PaintingItem extends Item{
parent::__construct(PAINTING, 0, $count, "Painting");
$this->isActivable = true;
}
private static $motives = array(
public 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),
"Kebab" => array(1, 1),
"Aztec" => array(1, 1),
"Alban" => array(1, 1),
"Aztec2" => array(1, 1),
"Bomb" => array(1, 1),
"Plant" => array(1, 1),
"Wasteland" => array(1, 1),
"Wanderer" => array(1, 2),
"Graham" => array(1, 2),
"Pool" => array(2, 1),
"Courbet" => array(2, 1),
"Sunset" => array(2, 1),
"Sea" => array(2, 1),
"Creebet" => array(2, 1),
"Match" => array(2, 2),
"Bust" => array(2, 2),
"Stage" => array(2, 2),
"Void" => array(2, 2),
"SkullAndRoses" => array(2, 2),
//"Wither" => array(2, 2),
"Fighters" => array(4, 2),
"Skeleton" => array(4, 3),
"DonkeyKong" => array(4, 3),
"Pointer" => array(4, 4),
"Pigscene" => array(4, 4),
"BurningSkull" => array(4, 4),
);
private static $direction = array(2, 0, 1, 3);
private static $right = array(4, 5, 3, 2);
@ -34,47 +40,21 @@ class PaintingItem extends Item{
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)];
if($face < 2 || $face > 5) return;
$data = array(
"x" => $target->x,
"y" => $target->y,
"z" => $target->z,
"yaw" => $faces[$face] * 90,
"Motive" => $motive[0],
"Direction" => match($face){
2 => 2,
3 => 0,
4 => 1,
default => 3
},
"xPos" => $target->x,
"yPos" => $target->y,
"zPos" => $target->z,
);
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
$server->api->entity->spawnToAll($e);