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

Floating text

Discussion in 'Development' started by Astro, Aug 30, 2018.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    Is there a way to make a block show a floating text when placing it?
     
  2. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    You can spawn a floating text to a player when they join.

    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $player $event->getPlayer();
        
    $text "Example text for the Floating Text";
        
    $position $player->getPosition()->asVector3()->add(0.500.5); //Where you want to spawn the floating text as a Position, to center the floating text I add 0.5 to x and z. (Not required, you can use the direct position)

        
    $player->getLevel()->addParticle(new FloatingTextParticle($position""$text));
    }
     
  3. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    i'm tryna make the floating text spawn when placing the item
     
  4. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    Use another event handler such as onPlace()
     
  5. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    alright thanks
     
  6. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    Are u having a certain block that does this?
     
  7. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    PHP:
        /**
         * @param BlockPlaceEvent $event
         */
        
    public function onPlace(BlockPlaceEvent $event) {
            
    $block $event->getBlock();
            
    $player $event->getPlayer();
            
    $vector = new Vector3($block->0.5$block->0.8$block->0.5);
            
    $particle = new FloatingTextParticle($vector""TextFormat::colorize(".a".$block->getName(), "."));
            
    $player->getLevel()->addParticle($particle, [$player]); // Remove the array if you want all the players to see the Particle.
        
    }
     
  8. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    this is what i've done so far
    PHP:
        public function onPlace(BlockPlaceEvent $e) {

            
    $item $event->getItem();


            if (
    $e->getBlock()->getId() == 54) {

                
    $damage $event->getItem()->getDamage();

                switch(
    $damage){
                    case 
    "1"
                    
    $item Item::get(5411);
                    
    $player $e->getPlayer();
                    
    $block $e->getBlock();
                    
    $x $block->getX();
                    
    $y $block->getY();
                    
    $z $block->getZ();

                    
    $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x 0.5$y 1.5$z 0.5), """§l§6Common §r§7Crate"), [$player]);
                    
    $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x 0.5$y 1.25$z 0.5), """§7Right-Click with a §6Common §7Key to redeem rewards"), [$player]);
                    
    $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x 0.5$y 1$z 0.5), """§7You can buy §6Common §7Keys from §eHestraPE.buycraft.net"), [$player]);
                    break;
                }
            }
        }
    }
    But is there a way to make the text not get removed when restarting server?
     
  9. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Store the texts and coords in a YML and load them onEnable()?
     
    NickTehUnicorn likes this.
  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.