Jump to content

[SOLVED][1.7.x]Can I force block updates to be more frequent for custom block


Recommended Posts

Posted

I have a custom block that will be very lightly used in the game -- only small number created by specific activity, and not on a creative tab.  Metadata is working fine for controlling an effect that I want, however I want the effect to change in a predictable pace but have been having trouble with  the block's updateTick() method.  It seems to be called very infrequently and very irregularly.

 

I noticed that the updates to block seem to be controlled by a queue of sorts and it seems to be possible on the WorldServer class to set an update for a block.  So I'm assuming I could try to put my block back on the queue on a regular basis. 

 

I realize I can use a tile entity, but it seemed that since metadata generally worked it would be interesting to do it this way.

 

Has anyone got any experience/advice on forcing block updates?  I'm thinking about just creating a server tick event handler and every few ticks forcing the update by calling the event on the world server.  But I'm worried that there might be some side effect to this, or alternatively maybe there is an easier way to ensure regular, speedy updates to a specific block type.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Use world.scheduleBlockUpdate(x, y, z, block, block.tickRate(world)) to immediately schedule an update tick; you may also want to notify neighboring blocks of the change. It's what most redstone blocks use to constantly tick, and I've used it to force tick updates on blocks when I want (for instance activating switches with a boomerang).

Posted

Use world.scheduleBlockUpdate(x, y, z, block, block.tickRate(world)) to immediately schedule an update tick; you may also want to notify neighboring blocks of the change. It's what most redstone blocks use to constantly tick, and I've used it to force tick updates on blocks when I want (for instance activating switches with a boomerang).

 

Perfect.  Thanks!

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

  • 3 months later...
Posted

Use world.scheduleBlockUpdate(x, y, z, block, block.tickRate(world)) to immediately schedule an update tick; you may also want to notify neighboring blocks of the change. It's what most redstone blocks use to constantly tick, and I've used it to force tick updates on blocks when I want (for instance activating switches with a boomerang).

I tried this and my block still didn't tick, so I looked at the declaration of scheduleBlockUpdate() and it did the most useful thing ever: {}. Any different methods that actually do something?

Posted

@cookie: That is because it only actually does something on the server. Show your code.

@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
	EntityPlayer player = world.getClosestPlayer(x+0.5, y+0.5, z+0.5, -1);
	if (player.getDistanceSq(x, y, z)>1 && player.inventory.hasItemStack(new ItemStack(MOD.ACTIVATED_ITEM, 1, 1))) {
		world.setBlock(x, y, z, Blocks.air, 0, 3);
	}
}

@Override
public boolean getTickRandomly() {
	return true; // Seems to be the only way to make it actually tick at all, tried removing, nothing happened
}

@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta) {
	world.scheduleBlockUpdate(x, y, z, this, 5);
	return meta;
}

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.