Fast Block Manipulation?

Discussion in 'Plugin Development' started by NerdsWBNerds, Apr 7, 2014.

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

    NerdsWBNerds

    How are plugins able to set and remove blocks so quickly without locking the main thread? For example, on minecraftparty.com, the 'wool mix-up' game removes and adds backs all the different colors of wools without locking the main thread. How do they do it?
     
  2. Offline

    rfsantos1996

    I don't know how many blocks you're planning to change, but depending on the server, you can easily change 500-750 blocks in some milliseconds.

    If is something that really lock the main thread (~25k blocks or more), create a qeueue system.

    Code:java
    1. // this inside a repeating task (control the block quantity/delay to run)
    2. thisRun = 0;
    3. if (queue.hasNext() && thisRun < 1000) {
    4. queue.next().setType(Material.WOOL);
    5. thisRun++;
    6. }
     
  3. Offline

    NerdsWBNerds


    I have a pretty decent dedicated server.
    I am using the following code to set the blocks.


    Code:java
    1.  
    2.  
    3. public void restore(){
    4. for(Tile tile: tiles){
    5. tile.generate();
    6. }
    7. }
    8.  
    9.  
    10. Tile class:
    11. public void generate(){
    12. for (Block set : blocks) {
    13. set.setType(Material.WOOL);
    14. set.setData((byte) c.getItemStack().getDurability());
    15. }
    16. }
    17.  


    There are 360 tiles in the tiles array, and 16 blocks in each blocks array
    so in total I should be generating 5760 blocks.
    It completely locks up the server thread for at least 5 seconds.
     
  4. Offline

    rfsantos1996

    Try queueing for 400 blocks per second?
     
  5. Offline

    NerdsWBNerds


    400 per second? Then it would take 14 seconds to change all the blocks. I need it to happen basically instantly. As I was saying, minecraftparty.com, the 'wool mix-up' game does this without little lag when changing all the blocks. and I don't think it's just because they have a godlike server
     
  6. Offline

    rfsantos1996

    You change 5.100 blocks on a row. If you change less blocks in more runs, it'll be smoother and less lagging.
    Try like... 200 blocks blocks per run, running each 7-13 ticks

    Well, CPU makes a HUGE difference, your plugins either...
     
  7. Offline

    xTigerRebornx

    NerdsWBNerds My guess is that the 'wool mix-up game' sends fake block updates to Player's and keeps the information about the blocks in the plugin, or it just changes such a small amount that it wouldn't cause too much lag.
     
  8. Offline

    ZeusAllMighty11

    If you're going to be doing a lot of complexity within a method, you should make it asynchronous. Obviously bukkit functions remain in the main thread.


    I've managed to set nearly a million blocks at once in ~700ms on a 2gb server with this.
     
  9. Offline

    NerdsWBNerds


    Thanks, would this work with spigot since it's calling upon craftbukkit, or no?


    If it sent fake block updates.

    A. How would you do that.
    B. Would people be able to fall through the fake updated air blocks?

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

    Tirelessly

    NerdsWBNerds these forums don't provide support for spigot.
     
    ZeusAllMighty11 likes this.
  11. Offline

    NerdsWBNerds


    This isn't specifically for spigot. Developing a plugin usually isn't different for plugin, unless you get into the types of things @ZeusAllMity11 was talking about. And that might even work with Spigot, I'm not sure. If it doesn't then I'll go on the Spigot forums and ask specifically how to port that code to Spigot.
     
  12. Offline

    ZeusAllMighty11

    My solution is compatible with Craftbukkit.
     
  13. Offline

    NerdsWBNerds


    But not Spigot (I don't know if there's some implementations of Craftbukkit in Spigot or something)
    If not I'll go on the Spigot forums and ask them what would be the Spigot equivalent (if I can't find out myself)
     
  14. Offline

    coasterman10

    Nearly everything that you can do on CraftBukkit will also work on Spigot because Spigot is a fork of CraftBukkit. If you are building against CraftBukkit and Spigot is throwing errors at you, you are using the wrong build. ZeusAllMighty11 's solution will work fine on Spigot if you use the right build.

    I don't understand why everyone instantly lashes out at Spigot being the issue. I have never, ever had issues working with NMS classes building against CraftBukkit while running on the same version Spigot server.
     
    TigerHix likes this.
  15. Offline

    NerdsWBNerds


    Thank you!


    The blocks are changing, but the client still has them rendered. They're gone upon relog. Any idea how to fix this?

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

    ZeusAllMighty11

    NerdsWBNerds

    Update the chunks and send them to the player
     
Thread Status:
Not open for further replies.

Share This Page