Replacing block

Discussion in 'Plugin Development' started by deathtaker26, Jan 9, 2013.

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

    deathtaker26

    So I have this code, but it doesn't seem to replace code, I don't understand what's wrong with it I read up on Block Loading and stuff but I just don't see to it working. What's wrong with it?

    I read up on block populators but I don't know how to use them as an event

    Code:
        @EventHandler
        public void onChunkLoad(ChunkLoadEvent event){
            Chunk chunk = event.getChunk();
            if(event.getWorld().getName() == "IceWorld"){
            for (int x = 0; x < 16; x++){
                for (int y = 0; y < 256; x++){
                    for(int z = 0; z <16; z++){
                        Block block = chunk.getBlock(x, y, z);
                        if(block.getType() == Material.NETHERRACK){
                            block.setType(Material.SNOW_BLOCK);
                        }
                        if(block.getType() == Material.LAVA){
                            block.setType(Material.WATER);
                        }
                        if(block.getType() == Material.SOUL_SAND){
                            block.setType(Material.ICE);
                        }
                        if(block.getType() == Material.NETHER_BRICK){
                            block.setType(Material.SMOOTH_BRICK);
                            }
                        if(block.getType() == Material.NETHER_BRICK_STAIRS){
                            block.setType(Material.SMOOTH_STAIRS);
                        }
                        if(block.getType() == Material.NETHER_FENCE){
                            block.setType(Material.COBBLE_WALL);
                        }
                        if(block.getType() == Material.FIRE);
                        {
                            block.setType(Material.AIR);
                        }
                        if(block.getType() == Material.RED_MUSHROOM){
                            block.setType(Material.AIR);
                        }
                        if(block.getType() == Material.BROWN_MUSHROOM){
                            block.setType(Material.AIR);
                        }
                        }
                        }
                    }
                }
                }
    } 
     
  2. Offline

    fireblast709

    second for-loop increments x instead of y
     
  3. Offline

    deathtaker26

    well that was an dumb mistake, Fixed that but still didn't work
     
  4. Offline

    slater96

    On this line
    Code:
            if(event.getWorld().getName() == "IceWorld"){
    The world name is a string so try doing .equals("IceWorld") and see if that fixes it.
     
  5. Offline

    deathtaker26

    I actually removed that line and tried it, no cigar!
     
  6. Offline

    slater96

    Have you registered the event?
    If you have then add some debug messages in to test.
     
  7. Offline

    deathtaker26

    the event works it's just not changing the blocks this was the code:
    Code:
        public void onChunkLoad(ChunkLoadEvent event){
            Chunk chunk = event.getChunk();
            getLogger().info("Chunk Loaded");
            //if(event.getWorld().getName().equals("IceWorld")){
            for (int x = 0; x < 16; x++){
                for (int y = 0; y < 256; y++){
                    for(int z = 0; z <16; z++){
                        Block block = chunk.getBlock(x, y, z);
                        if(block.getType() == Material.NETHERRACK){
                            block.setType(Material.SNOW_BLOCK);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.LAVA){
                            block.setType(Material.WATER);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.SOUL_SAND){
                            block.setType(Material.ICE);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.NETHER_BRICK){
                            block.setType(Material.SMOOTH_BRICK);
                            getLogger().info("Block Changed");
                            }
                        if(block.getType() == Material.NETHER_BRICK_STAIRS){
                            block.setType(Material.SMOOTH_STAIRS);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.NETHER_FENCE){
                            block.setType(Material.COBBLE_WALL);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.FIRE);
                        {
                            block.setType(Material.AIR);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.RED_MUSHROOM){
                            block.setType(Material.AIR);
                            getLogger().info("Block Changed");
                        }
                        if(block.getType() == Material.BROWN_MUSHROOM){
                            block.setType(Material.AIR);
                            getLogger().info("Block Changed");
                        }
                        }
                        }
                    }
    it returned Block Changed every time
     
  8. Offline

    CubixCoders

    Try
    block.setTypeId(Material.Whatever.id());
     
  9. Offline

    deathtaker26

    nope nothing
     
  10. Offline

    CubixCoders

    Maybe reload the chunk?
    e.getChunk().unload();
    e.getChunk().load();
     
  11. Offline

    deathtaker26

    If we reload the chunk it would be like leaving and coming back to it I don't see how this any different than that
     
  12. Offline

    CubixCoders

    Okay, then i don't know sorry D:
     
  13. Offline

    deathtaker26

    Tis cool, you tried, I for one am clueless
     
  14. Offline

    CubixCoders

  15. Offline

    deathtaker26

    Thanks for trying man!
     
  16. Offline

    fireblast709

    Just a tip, but you might want to run this only when isNewChunk(). Also you might want to replace Material.STATIONARY_LAVA with Material.STATIONARY_WATER. For the rest, try debugging the coordinates
     
  17. Offline

    deathtaker26

    I removed the coordinates and nothing.
     
  18. Offline

    Cjreek

    Nice idea!
    I'll try it at home later!

    Does the chunk have a setBlock() method or anything like this?
    If so then I would try this.

    Also try using a delayed task. I recently noticed that there are many things that don't work in events but they work a few gameticks later using a delayed task :)
     
  19. Offline

    Funergy

    deathtaker26
    If this worked for you
    Can you send me the code I have the same code you had and it doesn't work for me :/
     
Thread Status:
Not open for further replies.

Share This Page