1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Wings render code

Discussion in 'Development' started by ZackyVN, Sep 3, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Can someone update/fix Pemapmodded wings render code or something like that?
    PHP:
    $map = [];
    $handle $plugin->getResource("wings.map");
    $lines explode("\n"rtrim(stream_get_contents($handle)));
    fclose($handle);

    $height count($lines);
    foreach(
    $lines as $lineNumber => $line){
      
    $len strlen($line);
      for(
    $i 0$i $len; ++$i){
        if(
    $line{$i} === "X"){
          
    $map[] = new Vector2($i$height $lineNumber 1);
        }
      }
    }
    PHP:
    $scale 0.2;
    $particle = new FlameParticle(new Vector3);
    $yaw $player->yaw 180 M_PI;
    $xFactor = -sin($yaw) * $scale;
    $zFactor cos($yaw) * $scale;
    foreach(
    $map as $vector){
      
    $particle->$vector->y;
      
    $particle->$xFactor $vector->x;
      
    $particle->$zFactor $vector->x;
      
    $player->getLevel()->addParticle($particle);
    }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    I have created a plugin (quite some time ago) which can render a (custom format) wing.yml into a wing. I never finished it, but it is actually usable as a library in other plugins:
    PHP:
    //Display the given xxx.yml file (IN THE PlayerParticles plugin data folder) on a given $player:
    $wingName "Wing";
    /** $player Player The player you want to display the wing on. */
    $player//set this to your player (object!)

    $playerParticles->getPlayerManager()->addRenderJobToPlayer($player->getId(), new RenderJob($player$this->main->getModel($wingName)));
    (This is the map it reads: https://github.com/robske110/PlayerParticles/blob/master/Plugin/resources/wing.yml#L3) [why on earth did i use literal \n]
    You coud also just extract the wing render code out of it, but it is quite tangled in there. (Also the code is licensed under GPL-3.0)
     
  3. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    I tried to extract render code but it didnt go well
    https://imgur,com/a/RGLB64A
    code
    Task
    PHP:
            foreach($this->plugin->getServer()->getOnlinePlayers() as $player){
                
    $layout $this->plugin->getMap();
                
    $px $player->getX();
                
    $pz $player->getZ();
                
    $py $player->getY();
                
    $level $player->getLevel();
                
    $yOffset 2;
                
    $sp 0.25;
                
    $mb 0.25;
                
    $y $py $yOffset;
                
    $yaw $player->getYaw();
                
    $svp = (max($this->plugin->getstrlenMap()) * $sp 2) - $sp 2;
                
    $bx cos(($yaw 90) * self::DEG_TO_RAD) * $mb;
                
    $bz sin(($yaw 90) * self::DEG_TO_RAD) * $mb;
                
    $cosR cos($yaw * -self::DEG_TO_RAD);
                
    $sinR sin($yaw * -self::DEG_TO_RAD);
                foreach(
    $layout as $layer){
                    
    $y -= $sp;
                    for(
    $verticalPos strlen($layer) - 1$verticalPos >= 0$verticalPos--){
                        if(
    $layer[$verticalPos] === "X"){
                            
    $rx $svp $cosR;
                            
    $rz = -$svp $sinR;
                            
    $particleObject = new FlameParticle(new Vector3($px $rx $bx$y$pz $rz $bz));
                            
    $player->getLevel()->addParticle($particleObject);
                            
    $player->sendPopup("LOL");
                        }
                        
    $svp -= $sp;
    Main file
    PHP:
        public function getstrlenMap(){
            
    $map explode("\n""PXXXXXXXXXP\nPPXXXXXXXPP\nPPPPXXXPPPP\nPPPPXXXPPPP\nPPXXXXXXXPP\nPXXXXXXXXXP");
            foreach(
    $map as $key => $model){
                
    $strlenMap[$key] = strlen($map[$key]);
                return 
    $strlenMap;
            }
        }
     
        public function 
    getMap(){
            
    $map explode("\n""PXXXXXXXXXP\nPPXXXXXXXPP\nPPPPXXXPPPP\nPPPPXXXPPPP\nPPXXXXXXXPP\nPXXXXXXXXXP");
            foreach(
    $map as $line => $layer){
                
    $layer str_replace(" """$layer);
                
    $map[$line] = $layer;
                return 
    $map;
            }
        }
    This isnt my official plugin. Just a test to see its work or not
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    As I said it might be easier ti install the plugin and then use this simple code (in your own plugin) to spawn a wing on a given $player:
    PHP:
    $playerParticles $this->getServer()->getPluginManager()->getPlugin("PlayerParticles");
    //Display the given xxx.yml file (IN THE PlayerParticles plugin data folder) on a given $player:
    $wingName "Wing";
    /** $player Player The player you want to display the wing on. */
    $player//set this to your player (object!)

    $playerParticles->getPlayerManager()->addRenderJobToPlayer($player->getId(), new RenderJob($player$this->main->getModel($wingName)));
     
  5. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Can you explain the data["particles"];
    and $this->particleMap please?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.