World.getBlockAt(x,y,z).setType(NOT WORKING)?

Discussion in 'Plugin Development' started by TechGuard, May 17, 2011.

Thread Status:
Not open for further replies.
  1. I tried to use that, but no effects.. has it been changed?
    Or do I need to use the scheduler? (never used it)

    BTW, I get the world from this:
    Code:
    public void onChunkLoad(ChunkLoadEvent event){
        Chunk chunk = event.getChunk();
        World world = chunk.getWorld();
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  2. Offline

    axefan

    What are you passing to setType? It takes a Material object. Normally, I set blocks using setTypeId.
     
  3. Tried them both. Not working :(
     
  4. Offline

    axefan

    You'll need to provide a bit more info than "Not Working". I need an error message at least. Can you post some code?
     
  5. No errors at all!


    Code:
    for(int y = 127; y >= 0; y--){
                  for(int x = minX; x <= maxX; x++){
                    for(int z = minZ; z <= maxZ; z++){
                            world.getBlockAt(x,y,z).setTypeId(0);
                    }
                  }
                }
     
  6. Offline

    axefan

    That should work. Are you sure you're looking at the right block coords? Try setting the block under your player's feet as a quick test.

    Code:
    world.getBlockAt(player.getLocation()).setTypeId(0);
     
  7. Offline

    DreadKyller

    can you show where you get maxX maxY and maxZ?
     
  8. Will try to do some quick tests.
     
  9. Offline

    DreadKyller

    yah, because the getBlockAt(x, y, z).setTypeId(#) should work still, cause it works for my plugins.
     
  10. After some tests.. I think the Chunk.getX() and Y positions are wrong. I'm getting totally different numbers from them, as from the player position.
     
  11. Offline

    DreadKyller

    um, you would considering the chunk that is loading would be at the edge of the players sight.
     
  12. Can't be, I rember something like this: Chunk X: 15. Player X: 150
    Huge different
     
  13. Yeah, try and use block instead. Worked for me on my zombies plugin ;)
     
  14. Offline

    DreadKyller

    if you need to get the chunk the player in on, use world.getChunkAt(x, y, z)
     
  15. You don't understand. I'm using the OnChunkLoad event.
     
  16. Offline

    DreadKyller

    ok, here is what I am saying, you don't understand what I'm saying.

    you are useing on chunk load to load a cunk, however, the chunks that load by the Chunk load event are the chunks WAY out at the edges of your sight, the parts that slowly form when you move to enable you to see farther away, if you are trying to get a chunk near the player you need to change your method, because on chunk load will not work for your purposes if that is the case.
     
  17. All he wants is to change all the blocks in the loaded chunk to air, not the chunks the player is in or what-so-ever
     
  18. Offline

    DreadKyller

    ok, why even change the block to air, why not just cancel the event? cause then it will not even load to begin with.
     
  19. Offline

    vildaberper

    I didnt really read through the whole thread, but it sounds like youre setting a block at a chunk location.
    chunk.getX() is a chunk coordinate and not block. :)

    pseodocode:
    onChunkGenerate(blehEvent event){
    for(Block block : event.getChunk().getBlocks()){
    block.setTypeId(0);
    }
    }
     
  20. Chunk.getBlocks() doesn't exist..?
     
  21. Offline

    vildaberper

    Thats why i wrote pseudocode, youll have to do something like this:
    for(int x = 0; x < 16; x++){
    for(int z = 0; z < 16; z++){
    for(int y = 0; y < 128; y++){
    chunk.getBlockAt(x, y, z).setTypeId(0);
    }
    }
    }
     
  22. Yeh, tried that also :p

    Finally! Now I can see something, BUT this is the result:
    [​IMG]
    I'm almost sure it checks every chunk that passes through that event!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  23. Offline

    yottabyte

    Isn't that just what you want to do? When a chunk loads, set the entire chunk to air.
     
  24. Yes.. but why aren't the other chunk's set to air?
     
  25. Offline

    DreadKyller

    because they are loaded before the plugin loads I guess, otherwise i do not know.
     
  26. That's probably right because you get the "generating spawn area: x%" message
     
  27. Anybody knows how to fix it?
     
  28. Offline

    yottabyte

    Isn't there like a World.getLoadedChunks() or something? Too lazy to open Eclipse right now :p
     
  29. Offline

    DreadKyller

    yes, there is. What you would need to do though is make a boolean on the main class called used or somethng, to make this not go through more than once.

    Make a listener for player join, if the main class.used == false then get the world and do this:
    PHP:
    public void onPlayerJoin(PlayerJoinEvent event){
        if(!
    this.plugin.used){
            
    World world event.getPlayer().getWorld();
            for(
    Chunk chunk world.getLoadedChunks()){
                
    //do your chunk set to air stuff
            
    }
        }
    }
     
  30. No way.. I tought: "Thanks dude! that should work". Hahah... no it didn't :(
    It looks like getLoadedChunks() doesn't contain all of the chunks :O
     
Thread Status:
Not open for further replies.

Share This Page