Limiting lava flow to 25 blocks

Discussion in 'Plugin Development' started by rhunter, Apr 27, 2015.

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

    rhunter

    Hey i have been making plugins for a little while now and I wan't to make a plugin where it makes it so lava can only flow 25 blocks up and down.
    I don't even know where to start on this, but please don't say "go learn java first" because I know how to a lot of other stuff in java, i've just never gotten into something like this.

    Thanks in advance!
     
  2. Offline

    Konato_K

    @rhunter "go learn java first". Lol just kidding :p

    I'd go with BlockFromToEvent, when is called every time lava flows to one way ot another, then you get the block from where it's flowing and start going in a (probably recursive) way to get back to the source blocks or so.

    The Block class has operations to getBlock(BlockFace) on the relatives, hope this helped.
     
  3. Offline

    rhunter


    thanks for the quick reply!
    I don't really know how to put what you said in code form :p
    Would you mind giving me an example?
     
  4. Offline

    Konato_K

    @rhunter I'll just give you an idea, and here is the javadoc for the BlockFromToEvent, if you really want help then show what have you done and let's work with that.

    The getBlock method will return the lava block that is causing the move, the getToBlock method will return where the lava is, the idea is to use the Block from getBlock and then start checking on the sides what blocks are close to is, you can get the adjacent blocks like block.getRelative(BlockFace.UP), this will return the block above the other block, so the idea is just keep going up and the sides, if you find more than 25 blocks then you cancel the event.

    This may be a bit resource consuming, but I can't think of another way at the moment.
     
  5. Offline

    rhunter

    ok thanks I understand what those do now. I haven't started the plugin at all because I don't know what to do at all, thats why I asked if you could give me an example. So it seems pretty simple, I just don't know how to put it all together. Could you show me an example of it then I could edit it and learn from it an stuff? I am a very visual learner.
     
  6. Offline

    1Rogue

    Check for the placement of a lava source block, and generate a 26x26 ring (that's radius 25 + 1) around the perimeter of the placement (can also do a third dimension of y for blocking vertical flows). When lava enters that 26-block ring, deny the flow.
     
  7. Offline

    rhunter

    ok awesome. So how would i make the 26x26 ring? and im trying to make it so the lava cant flow 25 blocks on the y axis, up and down.
    heres my code so far:

    @EventHandler

    public void onPlayerPlace(BlockPlaceEvent e){
    if(e.getBlockPlaced().getType() == Material.LAVA_BUCKET){
    Bukkit.broadcastMessage(ChatColor.GOLD+"Lava flow is limited to 25 blocks on the y-axis.");
    }
    }
     
  8. Offline

    JUSTCAMH

    @rhunter Well one problem with using only the lava buckets is in the nether lava spawns in the ceiling and flows down. If you just use the bucket, the lava spawned naturally in the nether wouldn't be affected
     
  9. Offline

    rhunter

    I only care about the normal world. the nether is fine.
     
  10. Offline

    1Rogue

    Make a class for it, and keep that in a collection:

    Code:java
    1. public class Ring {
    2.  
    3. public Ring(Location origin, int radius) {
    4. //radius + 1
    5. //assign fields
    6. }
    7.  
    8. public boolean block(Location flow) {
    9. return Math.abs(flow.getBlockX() - origin.getBlockX()) != radius
    10. || Math.abs(flow.getBlockY() - origin.getBlockY()) != radius
    11. || Math.abs(flow.getBlockZ() - origin.getBlockZ()) != radius
    12. }
    13.  
    14. //implement #equals and #hashcode
    15.  
    16. }


    Code:java
    1. public class LavaListener implements Listener {
    2.  
    3. private Set<Ring> blocked = new HashSet<>();
    4.  
    5. //on placement, add new Ring to set
    6.  
    7. //on lava flow, test the new flow location against all rings in the set
    8.  
    9. }


    I wrote a good majority of it, you should be able to figure it out from there.
     
    Konato_K likes this.
Thread Status:
Not open for further replies.

Share This Page