how do i make a lightweight projectile lifespan procedure for rapid fire

Started by potatomancer on

Topic category: Help with Minecraft modding (Java Edition)

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do i make a lightweight projectile lifespan procedure for rapid fire

im trying to make a ranged item that has short range projectiles and shoot constantly while active enabled. i have tried a wait __ ticks then on server side on server side do despawn entity, but this causes the game to pretty much die (all mobs despawn and new chunks struggle to load). i have tried adding a cooldown to the ranged item, but i cant have the game run and the ranged item fire fast enough at the same time. is there any way to set a timer thats less asking of the game performance?

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could probably do an nbt…
Fri, 10/03/2025 - 22:11

You could probably do an nbt number tag on the immediate source entity (the projectile itself) which goes up by 1 on each projectile flying tick, and despawns the immediate source entity once it reaches a certain number (greater than or equal to 20 for example, to make it last for a second).

This works a lot better than the wait _ ticks procedure block, because that procedure block really doesn't work at all for what you are trying to do. (It has a few very specific use cases, but generally, you want to use an alternative timer method, like the one I described)

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i havent used nbt blocks…
Fri, 10/03/2025 - 22:41

i havent used nbt blocks before, so im not sure if im doing something wrong, but i got the same results as the previous code. heres the generated code

package net.mcreator.bluedwarf.procedures;

/* imports omitted */

public class ChainsawSparksWhileProjectileFlyingTickProcedure {
public static void execute(Entity entity) {
if (entity == null)
return;
while (entity.getPersistentData().getDouble("lifespan") <= 2) {
entity.getPersistentData().putDouble("lifespan", (entity.getPersistentData().getDouble("lifespan") + 1));
}
if (!entity.level().isClientSide())
entity.discard();
}
}
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I would use an if/else block…
Fri, 10/03/2025 - 23:53

I would use an if/else block instead of a while block, using the same condition of lifespan <= 2, with the nbt increase inside the if do part, and the despawn in the else do part. The way the projectile flying tick trigger works is it calls it 20 times per second, and the nbt will stay between those times, so the first time the procedure triggers, it will set lifespawn to 1, the second time will add 1 and bring it to 2, and the third time will no longer be <= 2, so it will call the else condition and despawn the immediate source entity.

 

It would probably look something like (but not exactly like) this:

 

If nbt number lifespan of immediate source entity <= 2

Do set lifespan of immediate source entity to lifespawn of immediate source entity + 1

Else Do despawn immediate source entity

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i tried your new suggestion…
Sat, 10/04/2025 - 00:34

i tried your new suggestion but got similar results. i understand you specified the code is not exact, but i didn't know that else to add or remove from it. i think all the logic checks out and it would work for a single shot ranged item, but i need it to be lighter on processing power.

heres the code i have right now

package net.mcreator.bluedwarf.procedures;

/* imports omitted */

public class ChainsawSparksWhileProjectileFlyingTickProcedure {
public static void execute(Entity entity) {
if (entity == null)
return;
if (entity.getPersistentData().getDouble("lifespan") <= 2) {
entity.getPersistentData().putDouble("lifespan", (entity.getPersistentData().getDouble("lifespan") + 1));
} else {
if (!entity.level().isClientSide())
entity.discard();
}
}
}