Help With Procedures - delay block [Solved]

Started by DragenSlayor on

Topic category: Help with MCreator software

Joined Jul 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help With Procedures - delay block [Solved]
Mon, 11/19/2018 - 16:54 (edited)

Is there any way to wait in between each action in procedures? I'd like to know if theres a way.

Edited by DragenSlayor on Mon, 11/19/2018 - 16:54
Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
feather4011, use imgur
Wed, 05/30/2018 - 12:05

feather4011, use imgur

Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This works fine:   Custom…
Wed, 05/30/2018 - 14:27

This works fine:

 

Custom Code snippet (You can find this block under the "Advanced" section in your Procedure editor):

 

try{Thread.sleep(1000);}catch(InterruptedException ex){Thread.currentThread().interrupt();}

 

The 1000 in the brackets are 1000 milliseconds = 1 second, you can change that to what ever you want!

Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
  So if you create a block…
Wed, 05/30/2018 - 14:35

The procedure

 

So if you create a block and put this Procedure into the "Update Tick" section and place this Block somewhere...

You will get two sentences with a 1 second delay inbetween them 

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
darkster, does that freeze…
Wed, 05/30/2018 - 18:58

darkster, does that freeze the whole game for a second, or does mcreator automatically create a separate thread for the mod? i haven't had a chance to test the code myself.

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ok, but have you tested it?…
Wed, 05/30/2018 - 19:53

ok, but have you tested it? because word in the Minecraft modding forums is that Minecraft runs only on one thread, and if you sleep the whole thread, you will freeze the game.

Joined Dec 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I test it and I does Freeze…
Mon, 06/04/2018 - 20:12

I test it and I does Freeze the game

Joined Jun 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can also verify that…
Tue, 06/05/2018 - 03:04

I can also verify that thread.sleep freezes the game.

 

I'm trying to make a cooldown timer that *mostly* works:

procedure

 

If I use the custom code, the game will freeze for 1000 ms * the # of iterations in the while loop.  So, in this case, 60 (item 1) * 1000ms or 1 minute.  Now, if I get rid of the special code (item 2), the while loop is near instantaneous.  I even upped it to 10M and it's still instantaneous.  I don't know how to fix this. :/

 

(PS:  I hope the image posts...for some reason, in preview, it's showing up as a broken image link)

Joined Jun 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
  Oh, here's the screen shot…
Tue, 06/05/2018 - 03:07

 

Oh, here's the screen shot of what I'm trying.  Internet is hard.  :/

 

I know the logic works, because where I put item 2, I tested it by having it spawn a gem for each iteration.  Sure enough, got 60 gems as expected.  So, I don't know what # to put in item 1 so that it's not an instantaneous completion.  And the custom code snippet just freezes the game up.

*shrug*

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
We're going to have to use…
Tue, 06/05/2018 - 05:07

We're going to have to use the Forge scheduler. Maybe if enough people ask nicely for an event implementation of it, Pylo will put it in the next version :P

Joined Jun 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OK, I screwed with the code…
Wed, 06/06/2018 - 01:54

OK, I screwed with the code directly this time.  It compiles, at least, without errors; but the timer effect is still near instantaneous, so there's no cooldown. :/  I didn't bother with using the procedures GUI in MCreator and just mucked around directly.  Maybe if I can figure out the right order of everything, I'll do it that way.

Da code:

public class mcreator_procTimerTest {

	// Experimental code starts here
	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {

//          mcreator_VarListtestenvironmentmod.timerCooldown = ((int) 0);

          final Runnable counter = new Runnable() {
               public void run() {mcreator_VarListtestenvironmentmod.timerCooldown = ((double) (mcreator_VarListtestenvironmentmod.timerCooldown - 1));
              }
          };
		
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure procTimerTest!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure procTimerTest!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		World world = (World) dependencies.get("world");
		if ((mcreator_VarListtestenvironmentmod.isCooldown == (true))) {
			if (entity instanceof EntityPlayer && !world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(new TextComponentString("This item is still in cooldown."), (true));
			}
		} else {
			if (entity instanceof EntityPlayer && !world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(new TextComponentString("Setting cooldown..."), (false));
			}
			mcreator_VarListtestenvironmentmod.isCooldown = ((boolean) (true));
			mcreator_VarListtestenvironmentmod.timerCooldown = ((double) 30);
			final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
			while ((mcreator_VarListtestenvironmentmod.timerCooldown > 0)) {
                    executorService.scheduleAtFixedRate(counter, 0, 1, TimeUnit.SECONDS);
			}
			mcreator_VarListtestenvironmentmod.isCooldown = ((boolean) (false));
			if (entity instanceof EntityPlayer && !world.isRemote) {
				((EntityPlayer) entity).sendStatusMessage(new TextComponentString("Cooldown complete."), (false));
			}
		}
	}


	// Experimental code ends here

 

I'm not sure what I'm missing.  I threw a little bit of code in there to try and debug the issue, and it seems that I've somehow screwed up the while statement?  Because it appears the countdown keeps going even after "Cooldown complete" is executed.

Totally confused.  I'll look at it again when I have fresh eyes. :P

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Did you read the link i…
Wed, 06/06/2018 - 04:03

Did you read the link i posted to the forum discussing how to use the forge TickHandler? That's exactly what you're looking for, as far as schedulers go. It links to a more comprehensive tutorial as well: https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/…