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 a machine where I'd like things like energy capacity to be based on the meta data of the block. The meta data represents different stages of the machine. I'm having trouble delivering that data to the tile entity in a consistent way. Obviously, I shouldn't pass it to the tile entity in a constructor. Doing so doesn't work anyways because only the default constructor is called with the TileEntity is loaded from NBT. And the World member variable isn't available in the constructor when loading from NBT, so I can't poll that to get the metadata for the block.  I can store the meta upon creation and save/load it from NBT, but there's no guarantee that the "meta" NBT will be read before the "energy" NBT. If the energy is loaded first, it would be limited to the lowest capacity and energy may be lost. I could initialize it to the highest meta, but it all starts feeling pretty "hack"y at this point...

 

Looking it over, it appears the Thermal Expansion solves this issue by storing the machine type in the meta, and the machine stage in item NBT. I'm not entirely sure how this gets passed to the TileEntity, but I'm sure I can figure it out if I went down this route. But it's a pretty big code restructure. Is this indeed the best way to handle this? Or is there something I'm missing? It seems like it should be simple to get the block metadata in the TileEntity, but it's proving quite difficult. I've used it in some other places by just getting the block state, but that was always with fully initialized blocks and TEs. The difficulty I'm having is because I want to initialize TE data (like energy and fluid capacities) based on the metadata.

  • Author

Looking into Thermal Expansion further, it looks like what they do is pretty close to what I was saying. They pass the NBT data in the "onBlockPlacedBy" method of the Block (rather than passing it to the constructor). The TileEntity constructor sets the default energy capacity to an arbitrarily large value, which is then scaled down once onBlockPlacedBy is called or after the NBT is loaded.  So I guess for my current specific requirements, there's no real reason to restructure my block metadata. I guess TE does it this way to reduce block ids and/or prevent the need for a bunch of different block classes?

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.