Solved break 3x3

Discussion in 'Spigot Plugin Development' started by Soolz, Jul 27, 2018.

  1. Ok, so I've tried this code and more but I can't:

    Code (Java):
    public void breakBlocksInCube(Block start, int radius, Player p){
                if (radius < 0) {
                    return;
                }
                for (int x = radius; x <= radius; x++) {
                    for (int y = -radius; y <= radius; y++) {
                        for (int z = radius; z <= radius; z++) {
                            start.getRelative(x, y, z).breakNaturally(p.getInventory().getItemInMainHand());
                        }
                    }
                }
             }
           
            @EventHandler
            public void test(BlockBreakEvent e){
                Location loc = e.getBlock().getLocation();
                for (int x = loc.getBlockX() - 1; x <= loc.getBlockX() + 1; x++) {
                    for (int y = loc.getBlockY() - 1; y <= loc.getBlockY() + 1; y++) {
                      for (int z = loc.getBlockZ() - 1; z <= loc.getBlockZ() + 1; z++){
                        Block b = loc.getWorld().getBlockAt(x, y, z);
                        Location bLoc = b.getLocation();
                            e.setCancelled(true);
                            for (ItemStack drops : b.getDrops()) {
                              e.getPlayer().getInventory().addItem(new ItemStack[] { drops });
                            }
                            e.setCancelled(true);
                            b.breakNaturally();
                         
                       
                      }
                    }
                }
            }  

    What I'd like:

    [​IMG]

    [​IMG]
     
  2. Praya

    Benefactor

    use blockface to define loop block
     
  3. What have you tried? What have you failed at? Have you debugged?
     
    • Like Like x 1
  4. My problem is that the orange blocks are also destroyed, and I wish it were only for the blocks in red

    [​IMG]
     
  5. Do it from x - radius, y - radius, z-radius to
    x + radius, y+ radius, z + radius. ++x, ++y, ++z

    It will work in any direction
     
  6. You have to check the block face to only break the correct neighbouring blocks
     
  7. He does not need to do it.
    Getting the blocks from - radius x and y and z to + radius x and y and z (3 fors) and it is easily done
     
  8. Praya

    Benefactor

    yes he need blockface, because what he want is 3x3x1 not 3x3x3
     
    • Agree Agree x 3
  9. Ok, thank you!
     
    #9 Soolz, Jul 31, 2018
    Last edited: Oct 23, 2018