Infinite loops

Started by Sam_64 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Infinite loops

I'm trying to make an infinite loop that spawns in 10 creepers every 2400 ticks. I've tried stuff like 'while true do' and also 'repeat infinite times' but the game just broke. How can I fix this?

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The problem with your first…
Mon, 01/29/2024 - 23:36

The problem with your first two approaches is that, by default, procedures are supposed to operate during a single tick. The game can only move to on to the next tick once everything has been finished. So if you tell a procedure to loop infinitely, or to run a while loop that cannot finish, it will lag and then crash the game from memory overload. 

What you want to do is trigger something every tick. In your case, you would need some sort of timer, (a status effect, or a player-persistent number variable that counts down every tick), and a procedure that runs on player update tick, checking each tick if the timer is finished. (And if it is, spawning the creepers and resetting the timer.) Depending on how you want the creepers to spawn, there are different ways you would do this, but the basic principle is the same.

Joined May 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm making a mod with…
Sun, 05/04/2025 - 13:20

I'm making a mod with customizable entities with cosmetics. I was thinking of doing repeat 999999 times, since that's basically forever.

Joined May 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey, I'm trying to make a…
Sun, 05/04/2025 - 13:52

Hey, I'm trying to make a cosmetic for a custom entity. I want to teleport the cosmetic to teleport and face the same way the custom entity is facing.