Fetch 9 blocks below player

Discussion in 'Plugin Development' started by MrRump, May 12, 2014.

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

    MrRump

    Heeey ! :)

    I started learning how to write a little Bukkit plugin again, but I am currently stuck.

    I am trying (just for learning purposes) to write a "Jesus" method: Once a player walks on water, I want to transform that water block below him into ice, and then transform it back into water.

    It all works perfectly! I just put the location of the block in a Hashmap and then check it later. However, if you only transform the block right below the player, walking on water is no fun - because the block actually is not frozen before you are right above a new block, thereby the client always "assumes" that you are about to fall into water. No problem, I decided to just transform the 9 blocks below the player into ice, then the player should be able to walk fluently.

    I didn't expect it to be a problem, I just have to make an array and adjust the Z and X coordinates - at least that's what I thought. Somehow, it does not select the right blocks :(

    I am trying to select the blocks as followed:

    Code:java
    1. Location loc = player.getLocation();
    2. loc.setY(loc.getY()-1);
    3.  
    4. Location[] locations = new Location[9];
    5. for (int i = 0; i<3; i++) {
    6. for (int j = 0; j<3; j++) {
    7. locations[3*i+j] = loc;
    8. locations[3*i+j].setX(locations[3*i+j].getX()+j-1);
    9. locations[3*i+j].setZ(locations[3*i+j].getZ()+i-1);
    10. }
    11. }
    12.  


    But when I then try to set the blocks to ice:
    Code:java
    1. for (Location location: locations) {
    2. Block block = location.getBlock();
    3. if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
    4. block.setType(Material.ICE);
    5. }
    6. }
    7.  


    It works as if I hadn't changed any code - only the block below the player is frozen :(
     
  2. This solution is a bit longer, but it should work:
    Code:
    int x = l.getblockxX();
    int y = l.getBlockY();
    int z = l.getblockZ();
    Location l1 = new Location(l.getWorld(), x - 1, y, z);
    Location l1 = new Location(l.getWorld(), x - 1, y, z - 1);
    Location l1 = new Location(l.getWorld(), x - 1, y, z + 1);
    Location l1 = new Location(l.getWorld(), x + 1, y, z);
    Location l1 = new Location(l.getWorld(), x + 1, y, z + 1);
    Location l1 = new Location(l.getWorld(), x + 1, y, z - 1);
    Location l1 = new Location(l.getWorld(), x, y, z - 1);
    Location l1 = new Location(l.getWorld(), x, y, z + 1);
    
    That is a way to get the blocks around you.
    I use it, and with me it works.
     
  3. Offline

    thecrystalflame

    Code:java
    1.  
    2. Location location = blocklocation.subtract(1,0,1);
    3. List<Location> locations = new ArrayList<Location>();
    4. for (int x = 0 ; x < 2 ; x++) {
    5. for (int z = 0 ; z < 2; z++) {
    6. locations.add(location.clone().add(x,0,z));
    7. }
    8. }
    9.  
     
    rsod likes this.
Thread Status:
Not open for further replies.

Share This Page