Posted January 29, 20223 yr Hi there, I'm getting started in Forge after years in Spigot. In Spigot, there's a few simple methods like: plugin.getServer().getScheduler().runTaskLater(plugin, action, ticksDelay); plugin.getServer().getScheduler().runTaskTimer(plugin, action, ticksDelay, ticksRepeat); Each of these also have an asynchronous version as well. What would the Forge equivalent of these be? Thank you!
January 30, 20223 yr There isn't one, just create a tick event handler and count ticks yourself. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 30, 20223 yr Author 3 hours ago, Draco18s said: There isn't one, just create a tick event handler and count ticks yourself. Ah okay. Thank you!
January 21, 20241 yr I just came across the same topic myself and wanted to leave my solution for anyone in need in the future. Apologies if I shouldn't revive. Note: Using Forge 1.19 as of writing The quickest "two-liner" seems to be possible with a ScheduledExecutorService: ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.schedule(() -> doSomething(), time, TimeUnit.MILLISECONDS); Disclaimer: While I've confirmed that this works, I don't know if there exist strong conventions against using custom thread code, although this is a simple use. My specific use case was to throw a burst of projectiles in sequence after right-clicking only once. If that's relevant, here's a more comprehensive example: // Implementing the Item.use method to throw multiple projectiles over time public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) { ItemStack itemStack = player.getItemInHand(hand); int itemsToThrow = Math.min(itemStack.getCount(), BURST_COUNT); if (!world.isClientSide) { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); for(int i = 0; i < itemsToThrow; ++i) { executor.schedule(() -> throwItem(world, player, itemStack, randomsource), 200 * i, TimeUnit.MILLISECONDS); } } player.awardStat(Stats.ITEM_USED.get(this), itemsToThrow); if (!player.getAbilities().instabuild) { itemStack.shrink(itemsToThrow); } return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide()); } Edited January 21, 20241 yr by ChexxorDev
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.