Solved Turning All Blocks in World to Different Type?

Discussion in 'Plugin Development' started by Mattkx4, Mar 25, 2014.

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

    Mattkx4

    Allow me to elaborate my dilemma:

    I'm making a mini-game and I need to be able to look through the loaded chunks on the world and check if they are a certain type.

    Is there any easy code for this? Can someone point me in the right direction?

    Thanks in Advance!

    P.S. I do have other options, but those would probably be less reliable and harder to "configure".

    Bumpio :)

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

    TehVoyager

    Theres probably a better way than just going through the whole world. What exactly are you doing?
     
  3. Offline

    Mattkx4

    TehVoyager
    I would just like find all the blocks in the loaded chucks that are Wool.

    Well I actually have part of a solution:
    Code:java
    1. public void resetMap(Player player) {
    2. Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    3. for (int xI = 0; xI <16; xI++) {
    4. for (int yI = 0; yI <256; yI++) {
    5. for (int zI = 0; zI <16; zI++) {
    6. Block block = chunk.getBlock(xI, yI, zI);
    7. if (block.getType() == Material.WOOL) {
    8. block.setType(Material.GOLD_BLOCK);
    9. }
    10. }
    11. }
    12. }
    13. }


    Only problem with this code is, is that it only loads the current chunk... I need to get like a 5-10 chunk radius....

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

    blablubbabc

    There are methods in World to load and get certain chunks. Also you might want to consider to split the scanning of the chunks into smaller parts to not lag the server too much in 1 tick.
     
  5. Offline

    Mattkx4

    blablubbabc
    There is specifically 2 seconds dedicated to resetting the map, plus the server is dedicated to this mini game So lag is not an issue :p

    If I set variable the for loops to be like so:
    Code:java
    1. public void resetMap(Player player) {
    2. Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
    3. for (int xI = 0; xI <128; xI++) {
    4. for (int yI = 0; yI <256; yI++) {
    5. for (int zI = 0; zI <128; zI++) {
    6. Block block = chunk.getBlock(xI, yI, zI);
    7. if (block.getType() == Material.WOOL) {
    8. block.setType(Material.GOLD_BLOCK);
    9. }
    10. }
    11. }
    12. }
    13. }


    Note the first and third for loops.... Would it scan a 128 x 256 x 128 block radius instead of just the chunk?
     
  6. Offline

    blablubbabc

    Nope, by looking at the source code of craftbukkit I would guess it cuts your numbers down to numbers between 0 and 15. But you can use world.getBlockAt(..) to get the blocks from there instead, or have another loop to go over the chunks.
     
  7. Offline

    TehVoyager

    Mattkx4
    Depending on what type of minigame you're doing you could record everytime a wool is placed and then go through the list setting the block at the wool's location to air.
     
  8. Offline

    ean521

    TehVoyager

    I now assume this is solved? And I believe he wants wool to be changed to gold.
     
    Mattkx4 likes this.
Thread Status:
Not open for further replies.

Share This Page