Replacing Lava with Air in WE code

Discussion in 'Plugin Development' started by Mtihc, Oct 6, 2011.

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


    I have a problem when replacing Lava with Air, using WorldEdit.
    And I don't mean via the command. Because, "//replace 10,11 air" works great. (10 lava, 11 stationary_lava)

    Lava and Stationary_Lava
    A lot of lava is replaced, except for a bunch of lava that is "flowing" (not stationary).
    That lava is definately inside the region. And I have also defined that Lava ánd Stationary Lava must be replaced. But still it leaves a bunch of lava behind.

    Lava data values
    I have read that liquids such as Lava and Water can have data values (0x0, 0x2, 0x4, 0x6 and 0x8).
    I tried that too, in all possible ways. See code later on.

    My code and //replace differences
    So I covered that lava can be stationary, and not stationary. And I covered the data values.
    What else is there?

    Since the replace-command works perfect, it has to be possible.
    So I went looking for WorldEdit's source code. I found out that WorldEdit does it just a little bit differently than me.
    1. The EditSession class has 2 options for the replaceBlocks() method via overloading. I use one option, and WorldEdit's replace-command uses the other one. WorldEdit uses the one with a Pattern as parameter instead of BaseBlock.
    2. Another difference is, that WorldEdit gets a Set<BaseBlock> via WorldEdit.getBlocks(), and I just make a set, manually.
    Error when using getBlocks()
    Using a Pattern instead of BaseBlock was easy. But when I tried to use getBlocks() I get a huge error.
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'mycommand' in plugin MyPlugin v0.1
        at org.bukkit.command.PluginCommand.execute(
        at org.bukkit.command.SimpleCommandMap.dispatch(
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(
        at net.minecraft.server.NetServerHandler.handleCommand(
        at net.minecraft.server.NetServerHandler.a(
        at net.minecraft.server.Packet3Chat.a(
        at net.minecraft.server.NetworkManager.b(
        at net.minecraft.server.NetServerHandler.a(
        at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
        at net.minecraft.server.MinecraftServer.h(
    Caused by: java.lang.StackOverflowError
        at com.sk89q.worldedit.WorldEdit.getBlocks(
        at com.sk89q.worldedit.WorldEdit.getBlocks(
        at com.sk89q.worldedit.WorldEdit.getBlocks(
        at com.sk89q.worldedit.WorldEdit.getBlocks(
    My code
    Here's a snippet of my code:
            // this part is called once in a constructor
            this.editSession = worldEdit.createEditSession(player);
            // this is how I create the Pattern and Set<BaseBlock>
            // when I use this code, it gives me the huge error
            // FYI: wep is the WorldEditPlugin object
            try {
                lavaBlocks = wep.getWorldEdit().getBlocks(null, "10,11");
                airBlocks = wep.getWorldEdit().getBlocks(null, "0");
                lavaPattern = wep.getWorldEdit().getBlockPattern(wep.wrapPlayer(player), "10,11");
                airPattern = wep.getWorldEdit().getBlockPattern(wep.wrapPlayer(player), "0");
            catch (DisallowedItemException e2) { }
            catch (UnknownItemException e2) { }
            // this does the actual replacement
            // FYI: toBlocksPattern is a Pattern, but could also be a BaseBlock
            editSession.replaceBlocks(region, fromBlocks, toBlocksPattern);
            worldEdit.remember(player, editSession);
            editSession.flushQueue();// i do this everytime, don't know if that's necessary but WorldEdit does it too
            // this is how I used to make the blocks,
            // this worked, but left a lot of lava behind
            // don't be confused by toBlocks/fromBlocks
            // because I also use them the other way around.
    //        fromBlocks = new HashSet<BaseBlock>();
    //        fromBlock = new BaseBlock(0);// air
    //        fromBlocks.add(fromBlock);
    //        toBlocks = new HashSet<BaseBlock>();
    //        toBlock = new BaseBlock(11);// lava
    //        toBlocks.add(toBlock);
    //        toBlocks.add(new BaseBlock(11, 0x8));
    //        toBlocks.add(new BaseBlock(11, 0x6));
    //        toBlocks.add(new BaseBlock(11, 0x4));
    //        toBlocks.add(new BaseBlock(11, 0x2));
    //        toBlocks.add(new BaseBlock(11, 0x0));
    //        toBlocks.add(new BaseBlock(10));
    //        toBlocks.add(new BaseBlock(10, 0x8));
    //        toBlocks.add(new BaseBlock(10, 0x6));
    //        toBlocks.add(new BaseBlock(10, 0x4));
    //        toBlocks.add(new BaseBlock(10, 0x2));
    //        toBlocks.add(new BaseBlock(10, 0x0));
    So, unless I am missing something, I have to try and get WorldEdit.getBlocks() to work.
    Although, just a HashSet of BaseBlock objects should work too. Especially when I add one with every possible data value. So I don't understand what's going on here.
  2. make sure you have a compatible build, for now, try //set
    Mtihc likes this.
  3. Offline


    But I am already using WorldEdit 4.7 and CraftBukkit 1240.
    And //set does not replace lava with air. It replaces everything with air.

    Thanks for the input though.
  4. //replace lava 0
  5. Offline


    I know the command

    And by the way, //replace lava 0 doesn't work that great. Better use //replace 10,11 0

    But the thing is.... read my post

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 20, 2016
  6. well, try contacting the author, since we don't know much about the source code.
  7. Offline


    I guess you're right. Although it's open source. The code is right there.
    If someone can help, please do.
  8. I beleives its because 'flowing lava' 'lava' and 'stationary lava' are all different. :/
  9. Offline


    how are you wanting to do this.... as you said not via command, do you want it to change automatically when a lava block(10, 11) is placed
  10. Offline


    No, I made my own command that gradually makes the lava rise. That works perfect. Only, when the lava has risen to the max. All lava should be removed. Which doesnt work. Well, it does remove SOME lava. But it leaves alot behind.
  11. Offline


    ahh okay
  12. My pet hate! SO much I gotta get the time to fix in worldedit. Why dont you open it as an issue?
  13. Offline


    I think I covered all that with block-type 10 and 11. And all the data values.

    I didn't follow half of what you said. But I got the important part. I will soon open it as an issue as you said.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 20, 2016
  14. I hate iT how lava isnt both types
    Worldedit has a lot of bugs. I gotta fix when i get the time
    Since i wont get time soon, open issue
  15. Offline


    I opened an issue.

    Also, I think it could have something to do with the timing of replacement.

    I ám using BukkitScheduler. Which is synched with those server ticks.
    But lava probably doesn't flow every server tick. But every so-many server ticks.
    Maybe the replacement needs to be done at the correct interval.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 20, 2016
Thread Status:
Not open for further replies.

Share This Page