1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Loop blocks between two locations

Discussion in 'Java' started by MasterHunter2003, Aug 8, 2017.

  1. MasterHunter2003

    Joined:
    Jan 28, 2017
    Messages:
    23
    Likes Received:
    1
    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?
    Code (Java):
    1.  
    2. @EventHandler
    3.     public void onExplode(EntityExplodeEvent e){
    4.         if(e.getEntity() instanceof Creeper){
    5.             Creeper c = (Creeper) e.getEntity();
    6.             if(c.getCustomName() != null){
    7.               if(c.getCustomName().equalsIgnoreCase("Fire Creeper")){
    8.                  Location blockLoc = c.getLocation().add(6, 6, 6);
    9.                  Location blockLoc2 = c.getLocation().add(6, 6, 6);
    10.                  List<Block> blocks = getRegionBlocks(c.getWorld(), blockLoc, blockLoc2);
    11.                  for(Block block : blocks) {
    12.                      block.setType(Material.DIAMOND_BLOCK);
    13.                  }
    14.               }
    15.             }
    16.         }
    17.     }
    18.    
    19.     public List<Block> getRegionBlocks(World world, Location loc1, Location loc2) {
    20.         List<Block> blocks = new ArrayList<Block>();
    21.  
    22.         for(double x = loc1.getX(); x <= loc2.getX(); x++) {
    23.             for(double y = loc1.getY(); y <= loc2.getY(); y++) {
    24.                 for(double z = loc1.getZ(); z <= loc2.getZ(); z++) {
    25.                     Location loc = new Location(world, x, y, z);
    26.                     blocks.add(loc.getBlock());
    27.                 }
    28.             }
    29.         }
    30.  
    31.         return blocks;
    32.     }
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    Not sure if it would fix but do not create instance of locations, get it from blocks in World#getBlockAt
    Code (Java):
    1. blocks.add(loc1.getWorld().getBlockAt(x, y, z))
    Edit:
    The issue is here:
    Code (Java):
    1. Location blockLoc = c.getLocation().add(6, 6, 6);
    2. Location blockLoc2 = c.getLocation().add(6, 6, 6);
    You are getting the same location basically
     

Share This Page

Loading...