Jump to content

Recommended Posts

Posted (edited)

Hi,

I'm making a little mod and I want to use the new Forge Energy API with it - specifically, have a block receive and use power. After a couple hours on the interwebs, I couldn't find any good explanations of how to do this (I literally just have an EnergyStorage inside of a TileEntity at the moment). I would appreciate it if anyone could explain this or even just give me some basic code to learn from. (I'm brand new to the Capabilities system too, so a quick explanation of that wouldn't go amiss.)

Many thanks,

-Matthew

Edited by m_lugg
Posted

Explanation of capabilities: http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

 

Replace everything you've read with the energy API equivalent, and you've got a TileEntity capable of handling energy.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted (edited)

Thanks!

One quick question: How would I write the currently stored energy into NBT? I presume I would use ENERGY_CAPABILITY.writeNBT with my EnergyStorage as the first parameter; but I am confused as to what the EnumFacing is for.

EDIT: After a re-read, would I be correct in saying that that can be anything, since my EnergyStorage can be used from any face?

Edited by m_lugg
Posted

myEnergyStorage.writeToNBT()

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

There should be a method with a similar name (because I don't have Eclipse open and don't feel like finding it for you). Its not static, you call it on the energy storage instance itself.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

EnergyStorage doesn't implement INBTSerializable, so it doesn't have methods to read it from/write it to NBT. Either get the capability's IStorage (Capability#getStorage) and use that to read from/write to NBT or do it yourself (storing the energy in a single integer tag).

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

Sorry for the delay in replying. I've got everything working now, thanks :)

One last question; I'm making a block that I want to consume power. That's working fine, but the problem is if I place _ANOTHER_ block which consumes power next to it, it sees the capability and extracts energy from it. Should I remove the getCapability override, or is there another way to get around this?

Thanks

-Matthew

Posted

Don't worry, I figured it out. Energy cables are responsible for putting the energy into the machine, not the machine itself.

Thanks for all your help!

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.