Jump to content

How to update existing blocks on load?


Lycanus Darkbinder

Recommended Posts

I've been working on creating a SSP block that turns on / off much like the Redstone Lamp but without the need for redstone.

 

I'm curious though because if I place one down and turn it on and then log out, when I log back in it isn't glowing unless I toggle the switch again.

 

I incorrectly assumed that onBlockAdded() fired both when you placed the block and when the world was loaded. I looked at the various redstone*.java files but wasn't quite sure how it saves state from session to session.

 

Any advice (examples or things I can read) as to how you tell the world when it loads that block XYZ should be lit?

 

Thanks!

 

Link to comment
Share on other sites

I've been working on creating a SSP block that turns on / off much like the Redstone Lamp but without the need for redstone.

 

I'm curious though because if I place one down and turn it on and then log out, when I log back in it isn't glowing unless I toggle the switch again.

 

I incorrectly assumed that onBlockAdded() fired both when you placed the block and when the world was loaded. I looked at the various redstone*.java files but wasn't quite sure how it saves state from session to session.

 

Any advice (examples or things I can read) as to how you tell the world when it loads that block XYZ should be lit?

 

Thanks!

 

Link to comment
Share on other sites

Well, I figured it out so I'll post here in case any other newcomers get stuck...

 

There were actually two things I was doing wrong:

 

1. I commented out my scheduleBlockUpdate() inside onBlockAdded()

 

This is required to schedule the block for updates after logging out / in. Part of the data saved with the world is the tickRate for the block and when it's next scheduled

 

2. Existing blocks don't get updated after making changes

 

I made the code changes but the blocks that were already in the world needed to be destroyed and replaced. I should've realized this earlier but hey, it's late and I'm tired.

Link to comment
Share on other sites

Well, I figured it out so I'll post here in case any other newcomers get stuck...

 

There were actually two things I was doing wrong:

 

1. I commented out my scheduleBlockUpdate() inside onBlockAdded()

 

This is required to schedule the block for updates after logging out / in. Part of the data saved with the world is the tickRate for the block and when it's next scheduled

 

2. Existing blocks don't get updated after making changes

 

I made the code changes but the blocks that were already in the world needed to be destroyed and replaced. I should've realized this earlier but hey, it's late and I'm tired.

Link to comment
Share on other sites

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.