Advertisement
TungstenVn

EntityZ

Jul 6th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tungst_geo;
  4.  
  5. use pocketmine\plugin\PluginBase;
  6. use pocketmine\Player;
  7. use pocketmine\Server;
  8. use pocketmine\event\Listener;
  9. use pocketmine\command\Command;
  10. use pocketmine\command\CommandSender;
  11. use pocketmine\event\Event;
  12. use pocketmine\event\player\PlayerJoinEvent;
  13.  
  14. use pocketmine\entity\Skin;
  15. use pocketmine\utils\TextFormat as C;
  16.  
  17.  
  18. use pocketmine\entity\Entity;
  19. use pocketmine\math\Vector3;
  20. use pocketmine\entity\Human;
  21. use pocketmine\nbt\tag\CompoundTag;
  22. use pocketmine\nbt\tag\StringTag;
  23. use pocketmine\nbt\tag\ListTag;
  24. use pocketmine\nbt\tag\NamedTag;
  25. use pocketmine\nbt\tag\DoubleTag;
  26. use pocketmine\nbt\tag\ShortTag;
  27. use pocketmine\nbt\ReaderTracker;
  28. use pocketmine\nbt\NBTStream;
  29.  
  30. use tungst_geo\EntityZ;
  31.  
  32. class Main extends PluginBase implements Listener {
  33.  
  34.  
  35.     public function onEnable(){
  36.         $this->getLogger()->info("How to play enable");
  37.         $this->getServer()->getPluginManager()->registerEvents($this, $this);
  38.         Entity::registerEntity(EntityZ::class, true,["EnityZ",EntityZ::class]);
  39.        
  40.     }
  41.    
  42.  
  43.     public function onCommand(CommandSender $sender, Command $command, String $label, array $args) : bool {
  44.         if($sender instanceof Player){
  45.         switch(strtolower($command->getName())){
  46.             case "a":
  47.             $this->skin($sender);
  48.             break;
  49.             case "npc":
  50.             $this->createnpc($sender);
  51.            
  52.             break;
  53.         }
  54.         }else{ 
  55.         };
  56.         return true;
  57.     }
  58.    public function createnpc($sen){//$sen is sender from onCommand
  59.         $skin = $sen->getSkin();
  60.         $path = $this->getDataFolder() . "poop.png";
  61.         $img = @imagecreatefrompng($path);
  62.         $skinbytes = "";
  63.         $s = (int)@getimagesize($path)[1];
  64.         for($y = 0; $y < $s; $y++){
  65.             for($x = 0; $x < 64; $x++){
  66.                 $colorat = @imagecolorat($img, $x, $y);
  67.                 $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
  68.                 $r = ($colorat >> 16) & 0xff;
  69.                 $g = ($colorat >> 8) & 0xff;
  70.                 $b = $colorat & 0xff;
  71.                 $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
  72.             }
  73.         }
  74.         @imagedestroy($img);  
  75.      
  76.        $player = $sen;
  77.        $nbt = Entity::createBaseNBT($sen, null, $sen->getYaw(), $sen->getPitch());
  78.        $skinTag = $sen->namedtag->getCompoundTag("Skin");
  79.        assert($skinTag !== null);
  80.        $nbt->setTag(clone $skinTag);
  81.        $npc = Entity::createEntity("EntityZ",$sen->getLevel(),$nbt);
  82.        
  83.        $npc->setSkin(new Skin("nothing", $skinbytes, "", "geometry.poop", file_get_contents($this->getDataFolder() . "poop.json")));
  84.        $npc->sendSkin();
  85.        $npc->setScale(0.5);    
  86.    $npc->spawnToAll();
  87.    }   
  88.  
  89.  
  90.    
  91.    public function skin($player){
  92.         $skin = $player->getSkin();
  93.         $path = $this->getDataFolder() . "texture.png";
  94.         $img = @imagecreatefrompng($path);
  95.         $skinbytes = "";
  96.         $s = (int)@getimagesize($path)[1];
  97.         for($y = 0; $y < $s; $y++){
  98.             for($x = 0; $x < 64; $x++){
  99.                 $colorat = @imagecolorat($img, $x, $y);
  100.                 $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
  101.                 $r = ($colorat >> 16) & 0xff;
  102.                 $g = ($colorat >> 8) & 0xff;
  103.                 $b = $colorat & 0xff;
  104.                 $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
  105.             }
  106.         }
  107.         @imagedestroy($img);
  108.         $player->setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(),@imagecreatefrompng("texture.png"), $skin->getGeometryName(), $skin->getGeometryData()));
  109.         $player->sendSkin();
  110.         //$player->sendMessage("ok");
  111.     }
  112.    
  113. }
  114.  
  115. <?php
  116.  
  117. namespace Tungst_geo;
  118.  
  119. use pocketmine\entity\Human;
  120. use pocketmine\level\Level;
  121. use pocketmine\nbt\tag\CompoundTag;
  122. use pocketmine\Server;
  123.  
  124. use pocketmine\network\mcpe\protocol\EntityEventPacket;
  125. class EntityZ extends Human{
  126.    
  127.    
  128.     public function entityBaseTick(int $tickDiff = 1) : bool{
  129.         print("Hi");
  130.        
  131.        
  132.         return parent::entityBaseTick($tickDiff);
  133.     }
  134.     public function getName(): string{
  135.                 return "EntityZ";
  136.     }
  137.    
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement