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.

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

Featured Replies

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/

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

  • Author

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

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?

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

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.