Jump to content

[1.17] Loop stopping the game


lGuestll666l

Recommended Posts

When im using BlockEvent.EntityPlaceEvent to detect when block is placed

try {

    Thread.sleep(4000);

    event.getWorld().setBlock(event.getPos(), Blocks.AIR.defaultBlockState(), Constants.BlockFlags.BLOCK_UPDATE);

    LightningBolt bolt = new LightningBolt(EntityType.LIGHTNING_BOLT, event.getEntity().level);

    bolt.moveTo(new Vec3(event.getPos().getX(), event.getPos().getY() - 1, event.getPos().getZ()));

    event.getWorld().addFreshEntity(bolt);

    while (true) {

        Thread.sleep(1000);

        String msg = ChatFormatting.RED+"Hello : )";

        event.getEntity().sendMessage(new TextComponent(msg),event.getEntity().getUUID());

    }

} catch (InterruptedException e) { e.printStackTrace(); }

And the leave the world, game just infinity saving world screen.

Someone know how to make loop without infinity loading screen after leaving?

Link to comment
Share on other sites

30 minutes ago, diesieben07 said:

You need to count ticks. The game only runs one thread for the main logic. If you sleep there, you're stopping the whole game.

Also: That is not at all how you ever handle exceptions.

Can you send an example of counting ticks function please?

Edited by lGuestll666l
Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.