How on earth would i manage to code this

Discussion in 'Plugin Development' started by xXRobbie21Xx, Sep 7, 2014.

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

    xXRobbie21Xx

    Okay, hear me out, im attempting to create a gta/dayz server and i am starting to mess around with some basic features. I think it would be pretty cool if when a player hit a glass block, it will break. I know it sounds dumb but imagine if there is this window, i dont know maybe 5 by 5 glass blocks, and when a player hits one, they all break. So now this gives the affect of being able to break through windows.
    So obviously coding a simple feature that when you hit a glass block it breaks instantaneously, would be simple, but how would one go about breaking a whole window?

    Also, maybe a regen feature? After a while the glass blocks will begin to regenerate back to its original state? That would be sweet.


    Im not looking to get spoon fed some code, but a little guiding, idea generating, and advice would be awesome, considering im a bit new to this.
    Thanks in advance - rob
     
  2. Offline

    Gater12

    xXRobbie21Xx
    You can iterate through the blocks around them.
     
  3. Offline

    xXRobbie21Xx

    Gater12 Okay, i gotcha, iv never heard of that before, but ill take a look! Thanks!
     
  4. Offline

    Gater12

  5. Offline

    xXRobbie21Xx

    Gater12 Thanks, it sure will.

    Okay, after a bit of research, i have realised that this is beyond me, can someone throw me in the right direction? Any help is appreciated!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. Offline

    jpjunho

    xXRobbie21Xx
    Do do the breaking listen for a playerinteractevent and see if the action is left click block and if the clicked block is a glass and then use this method to find the nearby blocks:
    Code:java
    1.  
    2. public List<Block> getRelatives(final Block b, final Material m, final List<Block> blocos){
    3. if(!blocos.contains(b)){
    4. blocos.add(b);
    5. List<BlockFace> faces = Arrays.asList(BlockFace.UP, BlockFace.DOWN, BlockFace.SOUTH,
    6. BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST);
    7. for(BlockFace bf : faces){
    8. Block bl = b.getRelative(bf);
    9. if(bl == null) continue;
    10. if(bl.getType() == null) continue;
    11. if(bl.getType().equals(m) && !blocos.contains(bl)){
    12. getRelatives(bl, m, blocos);
    13. }
    14. }
    15. }
    16. return blocos;
    17.  
    18.  
    19. }
     
  7. Offline

    xXRobbie21Xx

    jpjunho Allright, awesome, that makes sense. Thanks man!

    Edit: I haven't tested this, so if any more input is always welcomed!
     
  8. Offline

    coasterman10

    Recursion is certainly a good way to do this. I would personally create a method that breaks the glass block at the given location, then goes to each block in the 6 cardinal directions (+/- x,y,z) and run the same method on those if they are glass. It would continue until all of the connected glass blocks have been reached, at which point it would stop.
     
Thread Status:
Not open for further replies.

Share This Page