"Dig a hole"

Discussion in 'Plugin Development' started by uyscutix, Jan 14, 2017.

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

    uyscutix

    Hi. I'm making a command where when it's executed, it digs a hole under the command sender (or if I want, I can change it to target player (in command argument)).

    For example, the command could be "/dig <player>" and the target player will have a hole being dug under them.

    How do I dig a hole on the target player?
    Note: not too wide, perhaps a 3x3 block hole that digs to the void.

    Bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 14, 2017
  2. Offline

    Zombie_Striker

    @uyscutix
    1. Create an int. This represents the delay between mining blocks.
    2. Create three for loops. They represent the XYZ. Assign the coords you want to be removed.
    3. Get the block at XYZ. Make this variable final
    4. Create a delayed task.
    5. Inside the task, get the block and use breakNaturally on it to mine it.
    6. Set the delay for the task equal to the int from #1
    7. After each time the y value changes, increase the int from #1 by some value (20L is 1 second, so to mine a layer every second, increase the int by 20L)
     
  3. Offline

    uyscutix

  4. Offline

    Zombie_Striker

    @uyscutix
    Nope. I, and no one here on the bukkit forums, will spoonfeed you code.

    Each step is a separate line of code. It should be easy to convert it. Try doing it, and if it does not work, post the code here.
     
  5. Offline

    uyscutix

    @Zombie_Striker I think I did it wrong.

    Code:
            if (cmd.getName().equalsIgnoreCase("dig"))
            {
              
                Player player = (Player) sender;
                int i = 0;
              
                Location x = new Location(player.getWorld(), 3, 1, 3);
                Location y = new Location(player.getWorld(), 3, 1, 3);
                Location z = new Location(player.getWorld(), 3, 1, 3);
              
                new BukkitRunnable()
                {
                    @Override
                    public void run()
                    {
                        player.getLocation().add(3, 1, 3); 
                    }
                }.runTaskTimer(plugin, 0, 5);
    Can't find the variable for breakNaturally();
     
  6. Offline

    Zombie_Striker

    @uyscutix
    Don't create the XYZ as locations, but as for loops. First, do the y. start at the player's y and loop down until it is 0. After that, do the XZ. They will start at the x-min or z-min and go up until it reaches the x-max or z-max.

    Also, don't add. What you want to do is set the block, not just change the location.
     
  7. Offline

    uyscutix

    @Zombie_Striker
    I have an issue creating the for loop.

    Code:
    for (Block block : p.getLocation().getY())
    {
                  
    }
    this gives out errors when trying to loop the Y-location.
     
  8. Offline

    JanTuck


    I dont think that is how he wanted it ;/

    Now to loop from your current location to 0 do something like.
    Code:
    for(int y = LocY; y >= 0; --y) {
    }
    
    Here we define y to be your current locations y, it runs if y > or = 0 and everytime it runs it minuses y with 1.
     
    Zombie_Striker likes this.
  9. Offline

    uyscutix

    Oh, that was what goes in the loop. Although, I got an error from the word "LocY" but my IDE doesn't seem to be good at auto importing, do you know the full org.bukkit import to LocY?
     
  10. Offline

    timtower Administrator Administrator Moderator

    @uyscutix It is a variable, the starting height
     
  11. Offline

    uyscutix

    @Zombie_Striker i've done the 3 for loops now but do not know what goes in them.

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("dig"))
            {
                Player p = (Player) sender;
               
                int LocX = 0;
                int LocY = 0;
                int LocZ = 0;
               
                for (int x = LocX; x >= 0; --x)
                {
                   
                }
               
                for (int y = LocY; y >= 0; --y)
                {
                   
                }
               
                for (int z = LocZ; z >= 0; --z)
                {
                   
                }
               
                return true;
            }
           
            return true;
        }
    
     
  12. Offline

    JanTuck

    Looks like he wants to mine the whole world out. Place the x and z loops inside of the y loop.

    Sendt fra min ALE-L21 med Tapatalk
     
  13. Offline

    uyscutix

    @JanTuck is this okay?

    Code:
                for (int y = LocY; y >= 0; --y)
                {
                    for (int x = LocX; x >= 0; --x)
                    {
                       
                    }
                   
                    for (int z = LocZ; z >= 0; --z)
                    {
                       
                    }
                }
               
                return true;
    
     
  14. Offline

    JanTuck

    No, not like that. I just have to visit my grandma and then ill be back to answer if you still havent got it.

    Sendt fra min ALE-L21 med Tapatalk
     
  15. Offline

    uyscutix

    @JanTuck you said to place them inside the y-loop. Should I put z in the x loop which is inside the y-loop?
     
  16. Offline

    JanTuck

    Mhm, X loop inside y loop z loop inside x loop. However the loops x and z does not have the corrdct parameters.

    Sendt fra min ALE-L21 med Tapatalk
     
  17. Offline

    uyscutix

    Edit: I think I did something wrong.

    Please tell me what I did wrong if it is.

    Code:
        int LocX = 0;
        int LocY = 0;
        int LocZ = 0;
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("dig"))
            {
                final Player p = (Player) sender;
               
                for (int y = LocY; y >= 0; --y)
                {
                    for (int x = LocX; x >= 3; --x)
                    {
                        for (int z = LocZ; z >= 3; --z)
                        {
                            final Block block = null;
                           
                            new BukkitRunnable()
                            { 
                                @Override
                                public void run()
                                {
                                    double x = p.getLocation().getX();
                                    double y = p.getLocation().getY();
                                    double z = p.getLocation().getZ();
                                   
                                    block.getLocation(p.getLocation());
                                    block.breakNaturally();
                                    LocY++;
                                }
                            }.runTaskTimer(plugin, 0, 5);
                        }
                    }
                }
               
                return true;
            }
           
            return true;
        }
    
     
    Last edited: Jan 15, 2017
  18. Offline

    uyscutix

    I need more help, it doesn't appear to do anything when I run the code.
     
  19. Offline

    timtower Administrator Administrator Moderator

    @uyscutix Probably because it runs at 0,0,0 and not at your location.
     
  20. Offline

    uyscutix

    Oh, will everything work once I change the integers after? :)
     
  21. Offline

    timtower Administrator Administrator Moderator

    @uyscutix You currently have them as fields.
    Don't do that, just put them in the onCommand and set them to the position of the player, or relative of the player.
     
  22. Offline

    uyscutix

    Done. Is this ok?
    Hopefully I haven't missed something.

    Code:
    public class Command_dig implements CommandExecutor
    {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("dig"))
            {
                final Player p = (Player) sender;
               
                int LocX = p.getLocation().getBlockX();
                int LocY = p.getLocation().getBlockY();
                int LocZ = p.getLocation().getBlockZ();
               
                for (int y = LocY; y >= 0; --y)
                {
                    for (int x = LocX; x >= 3; --x)
                    {
                        for (int z = LocZ; z >= 3; --z)
                        {
                            final Block block = null;
                           
                            new BukkitRunnable()
                            { 
                                @Override
                                public void run()
                                {
                                    double x = p.getLocation().getX();
                                    double y = p.getLocation().getY();
                                    double z = p.getLocation().getZ();
                                   
                                    block.getLocation(p.getLocation());
                                    block.breakNaturally();
                                }
                            }.runTaskTimer(plugin, 0, 5);
                        }
                    }
                }
               
                return true;
            }
           
            return true;
        }
    }
    
     
  23. Offline

    timtower Administrator Administrator Moderator

    @uyscutix Make sure to get the relative directions though.
    So x>= LocX+3
     
  24. Offline

    uyscutix

    Ok i've updated the for loops except LocY. Is everything all done now? If so, i'm going to test it to see if it works. :)

    Code:
                for (int y = LocY; y >= 0; --y)
                {
                    for (int x = LocX; x >= LocX + 3; --x)
                    {
                        for (int z = LocZ; z >= LocZ + 3; --z)
                        {
                            final Block block = null;
                           
                            new BukkitRunnable()
                            { 
                                @Override
                                public void run()
                                {
                                    double x = p.getLocation().getX();
                                    double y = p.getLocation().getY();
                                    double z = p.getLocation().getZ();
                                   
                                    block.getLocation(p.getLocation());
                                    block.breakNaturally();
                                }
                            }.runTaskTimer(plugin, 0, 5);
                        }
                    }
                }
    
     
  25. Offline

    timtower Administrator Administrator Moderator

    @uyscutix You never set block to anything.
     
  26. Offline

    uyscutix

    I need it set to break any type of block including bedrock but do not know how to do that; therefore I thought setting it to "null" means any block.
     
  27. Offline

    JanTuck

    @uyscutix

    I would suggest you learn some java.

    Code:java
    1. else if (strings[0].equals("dig")) {
    2. for (int y = (int) player.getLocation().getY(); y >= 0; --y) {
    3. for (int xOff = -5; xOff <= 5; ++xOff) {
    4. for (int zOff = -5; zOff <= 5; ++zOff) {
    5. Block block = new Location(player.getWorld(), ((int) player.getLocation().getX() + xOff), y, ((int) player.getLocation().getZ() + zOff)).getBlock();
    6. for (ItemStack drop : block.getDrops()) {
    7. player.getInventory().addItem(drop);
    8. }
    9. block.setType(Material.AIR);
    10. }
    11. }
    12. }
    13. }


    This code here digs a large area go ahead an rewrite it to fit your needs.
     
Thread Status:
Not open for further replies.

Share This Page