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.

Featured Replies

Posted

I have in item with a decay capability, which depends on the total world time (the item stores its 'birth time' and then calculates the difference from the current world time to get its level of decay). At the moment the default behaviour is that the items in the creative tabs are all given a 'birth time' of zero, which means they end up all being already rotten if the world has existed for a while.

 

I just experimented with using getSubItems to set the capability using the client world, but this is null when the creative tabs are worked out. Is there any way for me to set the item's capability data at the point when the creative inventory is opened, or when the item is picked up from it - rather than it being set at startup and never changing?

Edited by Jay Avery

I made a similar system at some point. While I was not using capabilities the logic should still be the same. Basically every time I need to check the rot I would check if the "birth time" is at 0, and if it is - set it to the current time and wait for the next check. It is farely unlikely that the player would obtain a food item with a birth tme of 0, but you could use -1 as a default value and then you can be sure that the item was spawned in rather than obtained in some other way. If your idea is that the capability can be attached to any item, not just some specific ones you could perform a player inventory iteration once in a while to check for this exact case. If you do it infrequently it will pretty much not matter performance-wise. 

  • Author

Oh thanks, that gives me some ideas. I'm not sure one birth time check would work though, because it's checked every time the item is drawn in a GUI (for the durability bar) - so the first time it was checked it would be updated and then subsequently it would have a 'valid' value and not be changed again. But maybe I can add a field to the capability to store whether it's in a creative tab (or somewhere else that needs it to be infinitely fresh), and if that's true then keep updating (or perhaps just ignore) the time.

  • Author

Update: I figured out that the tabs are repopulated from scratch whenever the creative inventory is opened, so the approach I first tried is right. I just had to add a null check to skip over the world time when the world doesn't exist yet.

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.