Jump to content

How to create an EnergyItem with CapabilityEnergy


Mattizin

Recommended Posts

So,

 

i learned how tu use Capabilities on TEs.

This is really simple.

I know the Energy Capability can also be used for Itemstacks, but how do i create an item that uses engery, has internal storage and more with the CapabilityEnergy so that for example my maschines can charge it.

I searched a lot the pat hours and only find tutorials or example code for the rf api(which only works with interfaces) or how to create own capabilities, which again isnt my goal ;)

 

I think i will just need a bit of a starting point here :(

Link to comment
Share on other sites

I don't understand what you're getting at here.

 

Do you not have an Energy framework API here?

 

In regards to your machine charging your items. You could give the item damage capabilities (this.setMaxDamage(int); ) and then programme it to "discharge" (take damage) as a visual representation of it. Your machines could be coded to look for instances of that item class type and if true, if you have internal energy stored and your machine is an energy provider, if the item's nbt is not full, internalMachineEnergy --; itemNBTEnergy ++; or something along those lines.

Link to comment
Share on other sites

You need to create an implementation of

ICapabilityProvider

to provide the

IEnergyStorage

instance. The

ICapabilityProvider

also needs to implement

INBTSerializable

to save the

IEnergyStorage

to NBT. Because you often need to implement these interfaces together, Forge provides the

ICapabilitySerializable

interface which is simply a combination of the two.

 

Once you have the

ICapabiltiyProvider

implementation, override

Item#initCapabilities

to create and return an instance of it.

 

This isn't specific to the energy capability, it applies to any capability you want an item to provide.

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.

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.