Solved Loop blocks between two locations

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Jan 28, 2017
23
1
0
53
Question: I am trying to make a fire creeper, problem is that the block looping doesn't seem to work. Does someone know how I could fix this?
Java:
@EventHandler
    public void onExplode(EntityExplodeEvent e){
        if(e.getEntity() instanceof Creeper){
            Creeper c = (Creeper) e.getEntity();
            if(c.getCustomName() != null){
              if(c.getCustomName().equalsIgnoreCase("Fire Creeper")){
                 Location blockLoc = c.getLocation().add(6, 6, 6);
                 Location blockLoc2 = c.getLocation().add(6, 6, 6);
                 List<Block> blocks = getRegionBlocks(c.getWorld(), blockLoc, blockLoc2);
                 for(Block block : blocks) {
                     block.setType(Material.DIAMOND_BLOCK);
                 }
              }
            }
        }
    }
   
    public List<Block> getRegionBlocks(World world, Location loc1, Location loc2) {
        List<Block> blocks = new ArrayList<Block>();

        for(double x = loc1.getX(); x <= loc2.getX(); x++) {
            for(double y = loc1.getY(); y <= loc2.getY(); y++) {
                for(double z = loc1.getZ(); z <= loc2.getZ(); z++) {
                    Location loc = new Location(world, x, y, z);
                    blocks.add(loc.getBlock());
                }
            }
        }

        return blocks;
    }
 
Not sure if it would fix but do not create instance of locations, get it from blocks in World#getBlockAt
Java:
blocks.add(loc1.getWorld().getBlockAt(x, y, z))

Edit:
The issue is here:
Java:
Location blockLoc = c.getLocation().add(6, 6, 6);
Location blockLoc2 = c.getLocation().add(6, 6, 6);
You are getting the same location basically