Started by
potatomancer
on
Topic category: Help with Minecraft modding (Java Edition)
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?
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)
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
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
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