Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to change block by touch?

Comments in 'Plugin Development' started by vcraftPE, Aug 30, 2016.

  1. vcraftPE
    Offline

    vcraftPE New Member

    Joined:
    Jan 20, 2016
    Posts:
    10
    Minecraft User:
    vcraft
  2. vcraftPE
    Offline

    vcraftPE New Member

    Joined:
    Jan 20, 2016
    Posts:
    10
    Minecraft User:
    vcraft
    like in this video in 3:20
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It never changed the block to TNT but I'll answer the question on title
    PHP:
    public function onPlayerInteract(PlayerInteractEvent $event) {
       
    $event->getBlock()->getLevel()->setBlock($event->getBlock(), Block::get(Block::TNT));
    }
    It won't do the same as in video because in the video the block was replaced by air and spawned Explosion with no terrain damage, Explosion::explodeA() AFAIR, here's the code for explosion, It's better to use InventoryOpenEvent
    PHP:
    public function onInventoryOpen(InventoryOpenEvent $event) {
       if(
    $event->getInventory() instanceof ChestInventory) {
             
    # Do some additional checks, like if the chest is an envoy (what a fancy name)
             # Transfer all items, there is way more efficient way to do this...
             
    foreach($event->getInventory()->getContents() as $item) {
                 
    $event->getPlayer()->getInventory()->addItem($item);
             }
             
    # Make an explosion

             # Remove block
             
    $event->getBlock()->getLevel()->setBlock($event->getBlock(), Block::get(0));
        }
    }
    There is class named Explosion but I'm not sure will it spawn sound and particles as well but you can try tho
    PHP:
    $explosion = new Explosion($event->getBlock(), 1$event->getBlock()); // Don't put size 0 to avoid 'division by zero'
    $explosion->explodeA();
    P.S. I'm the only one who dislikes kids who make minecraft videos?
    Nawaf_Craft1b, applqpak and MikkiMCPE like this.
  4. vcraftPE
    Offline

    vcraftPE New Member

    Joined:
    Jan 20, 2016
    Posts:
    10
    Minecraft User:
    vcraft
    Okay that helped Thanks
  5. vcraftPE
    Offline

    vcraftPE New Member

    Joined:
    Jan 20, 2016
    Posts:
    10
    Minecraft User:
    vcraft
    and lol
  6. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Don't really understand ExplodeA and ExplodeB, light me please?
  7. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    FYI : ExploisonSound are included exploison particle too
  8. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Why is using InventoryOpenEvent better than using PlayerInteractEvent?
    P.S. I hate those YouTubers who record themselves playing as well. They are just public relations experts. They don't really create anything for us, except for those who showcase their own creation, such as redstone mechanisms invented by themselves, showcases for their own plugins, etc.
    Primus likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    InventoryOpenEvent can only be fired if chest is correctly placed and has valid Chest tile attached

Share This Page

Advertisement