Skip to content

Instantly share code, notes, and snippets.

@Muqsit
Created January 26, 2020 07:41
Show Gist options
  • Select an option

  • Save Muqsit/42f6cd0334b90e7fa0a97ee4701c19d2 to your computer and use it in GitHub Desktop.

Select an option

Save Muqsit/42f6cd0334b90e7fa0a97ee4701c19d2 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
/**
* @name mobbspawner
* @main muqsit\mobspawner\Main
* @api 4.0.0
* @version 0.0.1
*/
namespace muqsit\mobspawner{
use pocketmine\block\tile\MonsterSpawner;
use pocketmine\block\tile\Tile;
use pocketmine\block\tile\TileFactory;
use pocketmine\block\VanillaBlocks;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\item\ItemIds;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\plugin\PluginBase;
final class Main extends PluginBase implements Listener{
private $scale = 1.0;
private $what = "";
protected function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
public function onPlayerChat(PlayerChatEvent $event) : void{
$message = $event->getMessage();
if(is_numeric($message)){
$this->scale = (float) $message;
}else{
$this->what = $message;
}
}
/**
* @param PlayerInteractEvent $event
* @priority NORMAL
*/
public function onPlayerInteract(PlayerInteractEvent $event) : void{
if($event->getItem()->getId() === ItemIds::STICK){
$event->setCancelled();
$pos = $event->getBlock()->getSide($event->getFace())->getPos();
$pos->getWorld()->setBlock($pos, VanillaBlocks::MONSTER_SPAWNER());
$tile = TileFactory::createFromData($pos->getWorld(), CompoundTag::create()
->setString(Tile::TAG_ID, TileFactory::getSaveId(MonsterSpawner::class))
->setInt(Tile::TAG_X, $pos->x)
->setInt(Tile::TAG_Y, $pos->y)
->setInt(Tile::TAG_Z, $pos->z)
->setFloat("DisplayEntityScale", $this->scale)
->setString("EntityIdentifier", $this->what)
);
$pos->getWorld()->addTile($tile);
var_dump($this->what);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment