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'm trying to implement a basic teleportation staff. I managed to get the basic tp functionality working, and am now trying to make it require electricity.

I'm overriding initCapabilities in the item's class, and I managed to get a capability provider working. The cap works perfectly fine, and it updates the itemstack's nbt data correctly, until I close the game and reload it. When I do that, the capability resets its energy to 0, without updating the NBT data.

What I would like to get is an item that doesn't lose all of its energy because I closed the game.

I already tried to set the cap's energy based on the nbt data of the itemstack, but that only exists on the server ("server thread"). On the client ("render thread"), it's null.
 

Here is the code, on github.

Can anyone fill me in as to what I'm missing?

  • Author

I updated my code. Now I only create the LazyOptional in the ICapabilityProvider constructor, and then always use the same. The other problem has changed, but it's still not correct.

 

I implemented INBTSerializable, but the capability's energy is still reset whenever I load the game. The bright side is that the nbt is no longer out of sync: it is reset to 0 as well.

 

What am I doing wrong? Why is the tag reset to 0, as opposed to remaining what it was when I last saved the game?

  • Author

Based on the output of /data get entity @s Inventory[0]

[11:34:29] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] Dev has the following entity data: {Slot: 0b, ForgeCaps: {Parent: {Energy: 200}}, id: "mymod:teleport_staff", Count: 1b}

There is an nbt tag called "ForgeCaps". With that name, I assume that's where caps are saved. It increases by 100 whenever I use the staff, and it is reset to 0 whenever I reload the game

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.