Chunk loading and falling blocks not working together?

Discussion in 'Spigot Plugin Development' started by danablend, Jun 18, 2016.

  1. I have this slew of code, where I spawn a falling beacon at a certain position, and I then chunk load it (so it spawns correctly and falls down without players having to go nearby). Now the problem is that it doesn't actually load this chunk properly. All it does is spawn the falling blocks. You actually have to get a player near them for it to even start to fall down! My code looks like this where I do it:
    Code (Text):
                Location blockLocation = new Location(world, x, y, z);
                blockLocation.add(0, 20, 0);
                Bukkit.getServer().createWorld(new WorldCreator(world.getName()));
                blockLocation.getChunk().load(true);
                blockLocation.getWorld().loadChunk(blockLocation.getChunk());
                blockLocation.getWorld().spawnFallingBlock(blockLocation, Material.BEACON, (byte) 0);
                blockLocation.getChunk().load(true);
                blockLocation.getWorld().loadChunk(blockLocation.getChunk());
                blockLocation.setY(blockLocation.getY() - 20);
    As you can see, I have tried allot of different loading methods, none of them have worked a single bit! You need the player to enter the area before the falling beacon actually appears and starts falling.
     
  2. Have you tried delaying the spawning of the falling blocks a few ticks after loading the chunks? Chunk loading takes a lot of time and is very disk i/o intensive. You can see similar behavior in vanilla minecraft very often with floating sand and gravel. It takes a block update right next to these "stuck" blocks to make them start falling.

     
  3. Ill give it a go with the delay, ill try 5 seconds, not sure if its enough but ill give it a try.
     
  4. Okay, I made it load the chunks, then spawn the block 5 seconds later (using a delayed task) It works better but its not 100% working. I have a counter for the beacons falling, I spawn 15 but it says 8 in the start then goes up as i enter the chunks manually, should I do anything differently? It says 8 beacons spawned correctly and hit the ground. Before, it said 1 or 2, so its doing better than before!
    Code (Text):
                Bukkit.getServer().createWorld(new WorldCreator(world.getName()));
                blockLocation.getChunk().load(true);
                blockLocation.getWorld().loadChunk(blockLocation.getChunk());
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    @Override
                    public void run() {
                        blockLocation.getWorld().spawnFallingBlock(blockLocation, Material.BEACON, (byte) 0);
                    }
                }, 100L);
     
  5. Try sending a physics update to the block (or one that touches it) a tick after its spawned in.
     
  6. I'm sorry, how do I send a physics update to the block?

    EDIT: Another thing i forgot to mention, is that you cannot actually see the falling blocks now. They do fall, but you can't see them before they hit the ground.
     
  7. https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/BlockState.html#update(boolean, boolean)

    block.getState().update(true, true);

    I thought you said no players were near them. So, of course you wont see them fall.
     
  8. I was trying it live, and you could first see the falling block when it actually hit the ground. It's supposed to spawn 20 blocks above the surface but its first visible on ground hit. Also I can't seem to be able to do block.getState().update(true, true) because I have a falling block object, not a block, so unless i can cast it to a block, its not possible.
     
  9. But you can update a block that touching it. See the video i posted, when he opens the chest its doing a block physics update, which unstucks the sand.

    As for it being invisible until it hits the ground, idk. Someone else will have to jump in here about that.
     
  10. So I should spawn a block next to it, send that block a physics update, and then despawn the block?
     
  11. Its worth a shot. No one is around to ever see it happen, if it works :p
     
  12. Hmmm doesn't seem to work. I tried on a local server, I made it so there would be some falling blocks spawning at a set location, and then some falling blocks spawning about 500 blocks away from that location. I started it, the ones located at myself spawned fine, I could see the falling blocks, but the counter didn't quite work, as the blocks 500 blocks away didn't actually get loaded until i teleported myself to their location.
    Code (Text):
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    @Override
                    public void run() {
                        blockLocation.getWorld().spawnFallingBlock(blockLocation, Material.BEACON, (byte) 0);
                        Block updater = blockLocation.getWorld().getBlockAt(blockLocation.add(0, 0, 1));
                        updater.setType(Material.BEDROCK);
                        updater.getState().update(true, true);
                        blockLocation.setY(blockLocation.getY() - 20);
                       
                        Bukkit.getScheduler().scheduleSyncDelayedTask(Envoys.getInstance(), new Runnable() {
                            @Override
                            public void run() {
                                updater.setType(Material.AIR);
                            }
                           
                        }, 2L);
                       
                    }
                }, 100L);
     
  13. I tried sand and gravel, neither works. You can see them fall (just like beacon) but they first start falling when the player enters the chunk (or nearby chunk)
     
  14. That's also what I thought about. The problem is that i'm creating a type of crate plugin where crates fall down and you claim loot. Those crates are normal chests, problem is just that the falling block (beacon) gets turned into the chest when it hits the ground (with a listener) so I'd have to reword it entirely if I should do that. I might just start recoding the spawning of these blocks so it will work out.
     
  15. If the crates fall into a location that isn't loaded then just place it on the highest location in your location, if it's loaded then make your cool effect, also i would check for ChunkUnloadEvent and if it has an active crate falling finish it or cancel the event.

    Also if you want to make the effect event it isn't loaded, you could don't spawn the Crate until a player loads the chunk, you send the message to the players with the locations, and when a player loads the chunk spawn it.