Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Feel bit noobish I couldn't work out this problem out and thought best to ask for help :)

 

Im trying to run multiple delays but one after the other.

 

Example of what i want the block to do when activated:

*Block runs first delay

*creates one layer of blocks

*runs second delay

*creates second layer of blocks and so on.

 

The code I've written so far: Am i missing something obvious or is their an easier way to run delays?

 

When I test this code It runs the first delay, doesn't spawn the blocks i want, runs second delay then spawns all the blocks at once.


public void delayInGame() throws InterruptedException
{
	Thread.sleep(200);
}

@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)
{
	if(world.isRemote) 
	{
	    return true;
	}

try {
/**Add Blocks lvl 1*/
world.setBlock*spawn block code here*
world.setBlock*spawn block code here*
this.delayInGame();

      } catch (InterruptedException e) {}
try {
      /**Add Blocks lvl 2*/
      world.setBlock*spawn block code here*
      world.setBlock*spawn block code here*
      this.delayInGame();

} catch (InterruptedException e) {}

Hi

 

In order to do a delay, you will need to wait a number of ticks (the game calls the "tick" 20 times a second).

You can't just stop the code for (say) 2 seconds because that will stop everything for 2 seconds, which is not what you want.

 

There are a few ways, perhaps the easiest is Block.updateTick (see BlockRedstoneLogic).  Your block will need to schedule itself to receive ticks (eg World.scheduleBlockUpdate) - see BlockRedstoneLogic.

 

Alternatively you could run it all from an ITickHandler. 

Depends on the behaviour you want.

 

-TGG

Ummm... Why do you go through the hassle (and performance overhead) of scheduled updates if you have a **** TileEntity anyways?!?

To be able to change the delays at will, or disrupt updates if anything "bad" happens.

Just count ticks in your TEs updateEntity method? :P

I know this method exists (and it is worth mentioning to OP's knowledge), but needs to be avoided in my case.

Concurrency issues between tile entity update, redstone power, user inputs, and setting blocks in world.

Not safe.

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.