Solution to "Wait time" for the ones that don't want to enter the code

Started by Kamikase3535 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Dec 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Solution to "Wait time" for the ones that don't want to enter the code
Sun, 07/07/2019 - 05:32 (edited)

If you don't want to make advanced modding and enter the code because you don't know java or any reason that you have, but you need a wait time block, yeah you read it well, Just 1 block to make a certain quantity of milliseconds to wait:

 

WaittimeBlockMake a Custom Code snippet and paste this code

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

You just have to put the number of milliseconds inside Thread.sleep(#) replacing the # symbol

To use it simply put this block between the code you want to occur from the start and the one that will occur at the end of the wait time

It may cause a little bit of lag.

Forget it, it causes a LOT of lag I'm using 10000 milliseconds and it lags for 10 seconds and then it starts counting other 10 seconds xd

 

Edited by Kamikase3535 on Sun, 07/07/2019 - 05:32
Minecraft uses a single…
Tue, 07/09/2019 - 13:00

Minecraft uses a single threaded model so you need to make delay using counters, not by true delay/sleep function.

Check this tutorial for example on one approach to this: https://www.youtube.com/watch?v=VXAPH0g9A00&list=PLAeL-oIFIEngE6jRgFYeFMfuj8WQsO3Ei&index=26&t=2s

Joined Dec 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Man, solving this problem is…
Sun, 10/29/2023 - 13:31
Man, solving this problem is very simple. Create a static class that extends Thread, pass the dependencies to it, and implement the procedure code inside it. By the way, the lag you mentioned is due to you sleeping on a thread like on player tick update.
public class ProcedureVerificaBlocoPedregulho extends ElementsVariosmodMod.ModElement {

	public ProcedureVerificaBlocoPedregulho(ElementsVariosmodMod instance) {
		super(instance, 5);
	}

	
	 
	static  class tarefa extends Thread{
		 private Map<String, Object>dependencies;
		 private Random r;
		public tarefa(Map<String, Object> dep){
			dependencies=dep;
			r=new Random();
			start();
		}
		public void run(){
			try{
				long millis=(long)(r.nextFloat()*(float)10*(float)1000);
				sleep(millis);
			}catch(InterruptedException ex){}
			int x = (int) dependencies.get("x");
			int y = (int) dependencies.get("y");
			int z = (int) dependencies.get("z");
			World world = (World) dependencies.get("world");
			{
				BlockPos _bp = new BlockPos((int) x, (int) y, (int) z);
				IBlockState _bs = Blocks.STONE.getStateFromMeta(0);
				IBlockState _bso = world.getBlockState(_bp);
				for (Map.Entry<IProperty<?>, Comparable<?>> entry : _bso.getProperties().entrySet()) {
					IProperty _property = entry.getKey();
					if (_bs.getPropertyKeys().contains(_property))
						_bs = _bs.withProperty(_property, (Comparable) entry.getValue());
				}
				world.setBlockState(_bp, _bs, 3);
			}
			if (((world.getBlockState(new BlockPos((int) (x + 1), (int) y, (int) z))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", (x + 1));
					$_dependencies.put("y", y);
					$_dependencies.put("z", z);
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
			if (((world.getBlockState(new BlockPos((int) (x - 1), (int) y, (int) z))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", (x - 1));
					$_dependencies.put("y", y);
					$_dependencies.put("z", z);
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
			if (((world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) z))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", x);
					$_dependencies.put("y", (y - 1));
					$_dependencies.put("z", z);
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
			if (((world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) z))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", x);
					$_dependencies.put("y", (y + 1));
					$_dependencies.put("z", z);
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
			if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) (z + 1)))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", x);
					$_dependencies.put("y", y);
					$_dependencies.put("z", (z + 1));
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
			if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) (z - 1)))).getBlock() == Blocks.COBBLESTONE.getDefaultState().getBlock())) {
				{
					Map<String, Object> $_dependencies = new HashMap<>();
					$_dependencies.put("world", world);
					$_dependencies.put("x", x);
					$_dependencies.put("y", y);
					$_dependencies.put("z", (z - 1));
					ProcedureVerificaBlocoPedregulho.executeProcedure($_dependencies);
				}
			}
	
		}	
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure VerificaBlocoPedregulho!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure VerificaBlocoPedregulho!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure VerificaBlocoPedregulho!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure VerificaBlocoPedregulho!");
			return;
		}
		tarefa t=new tarefa(dependencies);
	}
}

Ícone "Verificada pela comunidade"