Block push player

Discussion in 'Plugin Development' started by girardcome, Jun 22, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    girardcome

    Hello i'm making a plugin funny and i'm a little bit stuck in my code, i would like to spawn a falling block into a player's location, and when the falling block spawned the player is pushed out of the location where the falling block spawned...

    Here's a video about it :


    My code :
    PHP:
        @EventHandler
        
    public void onPlayerInteract(PlayerInteractEvent e) {
            
    Player p e.getPlayer();
                    if (
    p.getItemInHand().getType() == Material.REDSTONE_BLOCK
                            
    && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                        
    e.setCancelled(true);
                   
                        
    Block clickedBlock e.getClickedBlock();
                        
    Material clickedBlockMaterial clickedBlock.getType();

                        if(
    clickedBlockMaterial == Material.GRASS) {
                            
    p.getWorld().spawnFallingBlock(p.getLocation(), clickedBlockMaterial, (byte)0);
                        }
            }
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    @girardcome That is normal minecraft physics though.
     
  3. Offline

    girardcome

    So i tried with a non-solid block and it works i don't have any push, but i want to players see the normal block in player location (not non-solid block)
     
  4. Online

    timtower Administrator Administrator Moderator

    Part of the same physics. And redstone is apparently solid.
     
  5. Offline

    girardcome

    That's what i did, and it worked:
    PHP:
        Set<LocationnewBlock = new HashSet<>();

        @
    EventHandler
        
    public void onPlayerInteract(PlayerInteractEvent e) {
            
    Player p e.getPlayer();
            if (
    p.getItemInHand().getType() == Material.REDSTONE_BLOCK && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                
    e.setCancelled(true);

          
                
    Location loc = new Location(p.getWorld(), p.getLocation().getBlock().getX(), p.getLocation().getBlock().getY(), p.getLocation().getBlock().getZ());
                if (!
    newBlock.contains(loc)) {
                    
    Material leaves Material.LEAVES;
                    
    p.getWorld().spawnFallingBlock(p.getLocation(), leaves, (byte0);
                    
    newBlock.add(loc);
                    
    p.sendMessage("Added to newBlock list!");
                }
            }
        }
    Now i would like that each player who are looking on this bloc location, it will transform this bloc location into a real block (as an illusion)
     
  6. Offline

    KarimAKL

Thread Status:
Not open for further replies.

Share This Page