1.16.5 Water bubble function

Discussion in 'Spigot Plugin Development' started by CROACH, Jul 7, 2021.

  1. Hello.
    I am working on gadgets and now I want to make a gadget that once activated runs a function for 30 seconds which is going to create an air bubble (sphere in radius 5-7 blocks) and then follow him, and as he go it will replace all the water that was removed with the water, but I don't have idea where to start
     
  2. You have to use a bukkitrunnable that will spawn bubbles particles at player location +2Y and cancel this runnable after 30 seconds.
     
  3. Hello,
    maybe this helps you.
    If you have further questions, feel free to ask me!
     
    • Informative Informative x 1
  4. You added nothing to your post??
     
  5. Sorry my fault :)
     
    • Agree Agree x 1
  6. I meant not particles, but actual AIR blocks, it would work as for example they activate the tool, and then for 30 seconds it loops and creates AIR for 7 blocks in radius of player
     
  7. Here's how I would approach it:
    1. Make a function to get an ArrayList of all blocks within a certain radius of a player that are WATER.
    2. Schedule a repeating task to first get the ArrayList for the player's current position, then replace all the blocks in the ArrayList with AIR. See this link for how to schedule self-cancelling repeating tasks: https://bukkit.fandom.com/wiki/Scheduler_Programming#Self-Canceling_Example
    3. In that repeating task's run() method, schedule a delayed task to replace the blocks in the ArrayList with water.
    On the topic of (1), it might be easier to begin with to just use a cube (so you can make sure the other parts of the plugin work without getting stuck on making a sphere). One way to make a sphere out of a cube is to test each block in the cube to see if it is within a certain distance of the player, then remove it from the ArrayList if it is not. Let me know if this makes sense.
     
  8. It does make sense but I am pretty new to spigot development and also new to java so it would be hard for me to make it from the very beggining.
    Can you show me an example with use of other blocks?
     
    #8 CROACH, Jul 8, 2021
    Last edited: Jul 8, 2021
  9. An example of which step I suggested?
     
  10. if you could do it, everything
     
  11. For making the arraylist:
    1. Declare a new ArrayList<Location>
    2. You want every block in a cube around the player (at least for now) so you need to put every block in that cube in the ArrayList
    3. Use a triple for loop:
      Code (Java):
      ArrayList<Location> blockLocations = new ArrayList<Location>();
      int radius =  5;
      Location loc = player.getLocation();
      int X = loc.getBlockX();
      int Y = loc.getBlockY();
      int Z = loc.getBlockZ();
      for(int i = X - radius; i <= X + radius; i++){
          for(int j = Y -radius; j <= Y + radius; j++){
              for(int k = Z - radius; k <= Z + radius; k++){
                  blockLocations.add(loc.add(i,j,k));
              }
          }
      }
    4. You now have an ArrayList with all blocks within a certain radius of the player (in a cube).
    For scheduling the repeating task, I've already linked a good tutorial, so please ask specific questions about what you don't understand.
    (https://bukkit.fandom.com/wiki/Scheduler_Programming)

    For scheduling the delayed task within the repeating task, see above.