Hey, Im kinda new to forge modding and I was wondering which is the best way to implement a timer within a HarvestDropsEvent and a RightClickItem Events
Ive been using a java.util.TimerTask but it has had ticks sync issues.
I know this might be something simple but I havent been able to figure that out, thanks in advance.
Edit: Code added.
I just need the EntityFallingBlock to spawn every X seconds without using a java.util.TimerTask the way a Bukkit.getScheduler().sheduleSyncRepeatingTask for Spigot does.
Error:
Description: Exception in server tick loop
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1442)
at java.util.HashMap$KeyIterator.next(HashMap.java:1466)
at net.minecraft.entity.EntityTracker.tick(EntityTracker.java:295)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:854)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
at java.lang.Thread.run(Thread.java:748)
Code:
int i2 = 0;
int max = 5;
timer.schedule(new TimerTask() {
@Override
public void run() {
if (i2 >= max) this.cancel();
if (i2 >= max) return;
i2++;
EntityFallingBlock tnt = new EntityFallingBlock(world, pos.getX()+0.5, pos.getY()+10, pos.getZ()+0.5, Blocks.TNT.getDefaultState());
tnt.fallTime = 1;
world.spawnEntity(tnt);
}
}, 0, 500);