Jump to content

Recommended Posts

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) {}

Posted

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

Posted

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.

Posted

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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