Posted November 30, 201311 yr 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) {}
November 30, 201311 yr 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
November 30, 201311 yr You can look here. The "Animator" block does a bit more, but uses the same idea.
December 1, 201311 yr 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.
December 1, 201311 yr Just count ticks in your TEs updateEntity method? 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.