Jump to content

[1.12] Using Forge Energy (FE) - help still needed!


Recommended Posts

Posted (edited)

Hi,

I'm trying to implement energy into my mod and have decided to use Forge Energy. I am struggling to do this, however. I know that I need to create an energy class extending EnergyStorage for the storage, but even after watching a tutorial I found and studying the source code of existing mods (mainly because most mods have complex systems and implementations and I can't figure out which parts of their code are necessary for this), I am finding it difficult to figure out how to actually do this and get it to work, and so am looking for some in-depth assistance or tutorial, that assumes no prior knowledge when it comes to energy (as I have never used any kind of energy API at all before - some explanations of FE I found assume that the reader has experience with RF).

What functions do I need to override, what classes do I need to create to get a basic system working? I'm looking to include storage blocks, producing blocks and energy-using blocks (and items) and I think I want energy to be transmitted wirelessly.

 

Thank you! :)

Edited by Sommanker
Posted (edited)

I would highly recommend learning to use the RF Api by TeamCOFH. It is widely used and means you're mod would be much more compatible with others, which is always a plus. Though I've never worked with energy before, I would strongly suggest RF as the route you should take. There's more likely to be tutorials for the API compared to FE since it is so wide spread too.

 

P.S. After some quick search I found the GitHub for the Redstone Flux API, which seems to include small implementations of how to use the basic system

Edited by mysticalherobine
Posted
1 minute ago, mysticalherobine said:

I would highly recommend learning to use the RF Api by TeamCOFH. It is widely used and means you're mod would be much more compatible with others, which is always a plus. Though I've never worked with energy before, I would strongly suggest RF as the route you should take. There's more likely to be tutorials for the API compared to FE since it is so wide spread too.

Thanks for the recommendation, but from what I've seen recently, many mods are starting to drop support for RF and are starting to use FE/Tesla more and more instead, sources being things like this https://www.reddit.com/r/feedthebeast/comments/5defce/redstone_flux_and_energy_apis_in_111/?st=j6b7xwui&sh=9d527ad5 .

Admittedly, there are more tutorials so it would be far easier for me to get started with RF, but equally I think I would rather, if at all possible, go straight to what appears to be becoming the future popular API to use, and if not FE, then Tesla.

 

 

Posted (edited)
15 hours ago, mysticalherobine said:

I would highly recommend learning to use the RF Api by TeamCOFH

I would rather start with FE and not use RF, because the FE API is build into Forge itself and thus it is always available. You would also not run into problems when the RF API doesn't update anymore. Like I remember a time where the mods by TeamCOFH got the 1.7.10 version 2014 and three years later followed 1.10.2 skipping 1.8.9 etc.

Also most mods which support RF also support FE. More explanation on wether to use FE or RF or both might be found here:

https://minecraft.curseforge.com/projects/redstone-flux

 

16 hours ago, Sommanker said:

mainly because most mods have complex systems and implementations

Most mods have this complex implementations because they are supporting multiply energy APIs while converting the energy internally to the one which is requested as an output or they got their own energy API for internal uses and convert to RF or FE or whatever is required by the connected machines.

When searching for mods which support energy and don't have complex systems I would start searching for mods which just support FE or maybe even support FE and Tesla, but I would also suggest looking into mods which got a fresh rewrite as otherwhise it might be that at one point they added support for FE into their existing systems and later on removed all the other APIs which aren't needed and such code is harder to read when you've got no idea how it works.

 

15 hours ago, Sommanker said:

Admittedly, there are more tutorials so it would be far easier for me to get started with RF, but equally I think I would rather, if at all possible, go straight to what appears to be becoming the future popular API to use, and if not FE, then Tesla.

 

WARNING: I might have missed some things in the following description as my own energy system also supports Tesla and thus is a bit more complicated.

 

As a starting point for FE, I would highly suggest to learn about the Capability System by Forge, if you haven't already done this.

https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

This is required as the Forge Energy system is based around capabilities.

 

The next point would be create a new class extended from EnergyStorage or just implement all the code yourself using the IEnergyStorage interface which I would suggest if you plan on overwritting all methods provided in EnergyStorage anyway. This class should also implement the interface INBTSerializable<NBTTagCompound> if you want to store your energy data (I assume here that you are already familiar with Java Generics).

In this class, save your data and read it in using normal NBT read and write methods (serializeNBT and deserializeNBT). This methods will later be called in for example our TileEntity's NBT read and write methods. In a more advanced system you might also use the capability methods to call wrapper classes around FE and Tesla and other capability based energy systems in this class, but this is out of scope of this basic overview.

 

At next, you should create a TileEntity.

This TileEntity needs your EnergyManager class you created before (the class which extends EnergyStorage or implements IEnergyStorage ). 

In here you add the read and write methods for NBT data and call the serializeNBT and deserializeNBT methods of your EnergyManager.

For example:

this.container.deserializeNBT(compound.getCompoundTag("Energy"));

(container is here the instance of EnergyManager.)

 

Then you also need the hasCapability and getCapability methods. I think you figure yourself out what to put in there.

In the update method of your TileEntity you might want to put your logic about energy production or extraction in.

 

this.container.receiveEnergy(int maxReceive, boolean simulate);
this.container.extractEnergy(int maxExtract, boolean simulate);

 

If you want to extract or receive energy from another TileEntity, you first need to get it at the specific location and than get the capability at the specific side. (Note: If a machine only sends energy in other machines underneath, then it might only return a capability for EnumFacing.DOWN.) An EnumFacing with null is also possible and might be used for internal purposes if I recall correctly.

 

Do note that it is recommended for the most compatibility between mods to let your machines send the energy into the cables instead of letting the cables extract the energy out of your machines.

https://github.com/SleepyTrousers/EnderIO/issues/4081#issuecomment-284911416

 

I hope this gives you a basic overview of how energy systems actually work. For items, I currently having figured it out myself as I've not worked with items and capabilities so far and transmitting energy wirelessly shouldn't be a challange after reading this. The basics are always the same, just how much more you put around those basic is different.

Edited by Bektor
  • Like 2
  • Thanks 1

Developer of Primeval Forest.

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.