Jump to content

Recommended Posts

Posted

Hey everyone,

I am coding a freezer for food (in my mod food can decay)

My problem right now is when the freezer gets unloaded (playerr moves away from it) time keeps passing in the world. So when the freezer reloads I need to check how much time has passed, decrement the amount of coolant and if there is not enough coolant reduce the durability of the food.

 

I need the actual world time to check that and wanted to access the worldObj in readFromNBT, but im getting a NPE. I know I can acess an worldObj via MinecraftServer but I feel like this is a dirty way and im asking for the better one.

 

Any help is appreciated

Greetz Fail

Posted

I don't think this is possible, since the

TileEntity

isn't added to the

World

until after it's been loaded from NBT.

 

Instead, I'd recommend setting a flag in

readFromNBT

and then checking for this flag in your update method. If it's

true

, set it to

false

and then perform the load-time coolant calculations.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Actually, I just remembered that Forge recently added the

TileEntity#onLoad

method, which is called when the

TileEntity

's block is first placed in the world and when its chunk is loaded from NBT. You should be able to override this to do the coolant calculations instead of using the flag in the update method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

/**

* Called from the Chunk when this is first added to the world. Override instead of adding

* if (firstTick) stuff in update. Happens after validate and after it has been placed into the Chunk tileEntity

* map.

*/

 

Best.comment.ever.

 

 

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.