Jump to content

Recommended Posts

Posted

Hey everyone,

I am trying to implement ForgeEnergy as a second energy system in addtion to RF (and later also TELSA). I want to implement it in an item class wich extends the ItemArmor class. The page on ReadTheDocs about capabilities only describes it for TEs and ItemStacks... I am completly new to the capability system so I have absolutly no plan what to do.

Maybe someone can explain it to me in a few sentences and can even provide an example.

If it helps, the class I am talking about is this one: https://github.com/CyberdyneCC/SimplyJetpacks-2/blob/TomsonDev/src/main/java/tonius/simplyjetpacks/item/rewrite/ItemFluxpack.java

 

Tomson124

Posted (edited)

Item capabilities are handled differently to Entity/TileEntity capabilities because Items are singletons, i.e. there's only one instance per item type.

 

Instead of Item implementing ICapabilityProvider directly, it has a method (Item#initCapabilities) that creates and returns a separate ICapabilityProvider instance. ItemStack (which implements ICapabilityProvider) calls this method from its constructors and stores the returned ICapabilityProvider, using it in its own implementation of the interface.

 

You can see some examples of items with capabilities here, here, here, here and here.

 

These all use one of two ICapabilityProvider implementations: CapabilityProviderSimple (only implements ICapabilityProvider, doesn't save/load capability data) and CapabilityProviderSerializable (implements both ICapabilityProvider and INBTSerialializable so it saves/loads capability data).

Edited by Choonster
  • Like 1

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
  On 4/15/2017 at 1:02 PM, Choonster said:

These all use one of two ICapabilityProvider implementations: CapabilityProviderSimple (only implements ICapabilityProvider, doesn't save/load capability data) and CapabilityProviderSerializable (implements both ICapabilityProvider and INBTSerialializable so it saves/loads capability data).

Expand  

Thank you.

If I am right, I don't have to make my own ICapabilityProviders if I just use the default implementation from ForgeEnergy, right? Or do I need to do the exchange between ForgeEnergy and RF in the CapabilityProvider Implementation?

Posted
  On 4/16/2017 at 11:55 AM, Tomson124 said:

Thank you.

If I am right, I don't have to make my own ICapabilityProviders if I just use the default implementation from ForgeEnergy, right? Or do I need to do the exchange between ForgeEnergy and RF in the CapabilityProvider Implementation?

Expand  

 

The ICapabilityProvider is responsible for storing the IEnergyStorage instance and providing it to external code. The IEnergyStorage implementation should be a completely separate class that stores the energy value and allows interaction with it through the IEnergyStorage methods.

 

You will need to create your own ICapabilityProvider implementation, Forge doesn't provide a stand-alone implementation for your use-case. The only implementations apart from vanilla classes are CapabilityDispatcher, which is designed to wrap multiple ICapabilityProviders into one; and FluidHandlerItemStackFluidHandlerItemStackSimple and FluidBucketWrapper, which implement IFluidHandlerItem in various ways.

 

If you want the RF IEnergyContainerItem and Forge IEnergyStorage interfaces to interact with the same energy value, you'll need to implement that yourself. There are two ways to do this:

  • Keep the current IEnergyContainerItem implementation and create an IEnergyStorage implementation that delegates to it
  • Use the default IEnergyStorage implementation (EnergyStorage) and change the IEnergyContainerItem implementation to delegate to it

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

So to sum this up, I have to create my own CapabilityProvider which is then used in initCapabilities and I have to make a custom implementation of IEnergyStorage (like EnergyStorage) which also includes interaction with IEngeryContainerItem. But how do I tell the ForgeEnergy Capability that it has to use my custom IEnergyStorage implementation instead of the default one?

Posted
  On 4/16/2017 at 8:10 PM, Tomson124 said:

So to sum this up, I have to create my own CapabilityProvider which is then used in initCapabilities and I have to make a custom implementation of IEnergyStorage (like EnergyStorage) which also includes interaction with IEngeryContainerItem. But how do I tell the ForgeEnergy Capability that it has to use my custom IEnergyStorage implementation instead of the default one?

Expand  

 

Your ICapabilityProvider class should store an instance of this custom IEnergyStorage implementation and return it from ICapabilityProvider#getCapability when the Capability argument is CapabilityEnergy.ENERGY. This is what allows other mods to access your IEnergyStorage instance.

 

You can either create the IEnergyStorage instance in the ICapabilityProvider or create it in the Item#initCapabilities override and pass it to the ICapabilityProvider's constructor.

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 (edited)

So I think I got it right, at least I did so until I ran into the first errors :/

It currently looks like this:

  Reveal hidden contents

 

Edited by Tomson124
Adjusted Spoilers
Posted

The RF API requires you to implement IEnergyContainerItem on an Item, it doesn't support capabilities.

 

Why does EnergyConversionStorage have an IEnergyStorage field?

 

If you're delegating the IEnergyStorage methods to the IEnergyContainerItem methods, EnergyConversionStorage should only implement IEnergyStorage without extending EnergyStorage. It should have an ItemStack field so it can call the IEnergyContainerItem methods on the Item.

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
  On 4/17/2017 at 7:57 AM, Choonster said:

The RF API requires you to implement IEnergyContainerItem on an Item, it doesn't support capabilities.

 

Why does EnergyConversionStorage have an IEnergyStorage field?

 

If you're delegating the IEnergyStorage methods to the IEnergyContainerItem methods, EnergyConversionStorage should only implement IEnergyStorage without extending EnergyStorage. It should have an ItemStack field so it can call the IEnergyContainerItem methods on the Item.

Expand  

The field was just a remaing piece of code from an earlier attempt...

 

I now changed the EnergyConversionStorage like you said:

  Reveal hidden contents

And I adjusted the initCapabilities accordingly:

@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) {
	return new CapabilityProviderEnergy<>(new EnergyConversionStorage(this, stack), CapabilityEnergy.ENERGY, null);
}

But when I start minecraft, or more specifically when I load a world it crashes with the error:

  Reveal hidden contents

 

Posted (edited)
  On 4/17/2017 at 12:30 PM, Tomson124 said:
java.lang.IllegalArgumentException: Can not deserialize to an instance that isn't the default implementation
	at net.minecraftforge.energy.CapabilityEnergy$1.readNBT(CapabilityEnergy.java:30)
	at net.minecraftforge.energy.CapabilityEnergy$1.readNBT(CapabilityEnergy.java:19)
	at net.minecraftforge.common.capabilities.Capability.readNBT(Capability.java:99)
	at tonius.simplyjetpacks.capability.CapabilityProviderEnergy.deserializeNBT(CapabilityProviderEnergy.java:49)

 

Expand  

 

The IStorage for the energy capability (used by Capability#readNBT) can only desrialise from NBT into an instance of EnergyStorage. This is a general rule for most capabilities: The IStorage is only guaranteed to work with the capability's default implementation. If you're using a custom implementation, you'll need to read from/write to NBT yourself (or use that implementation's methods if it implements INBTSerializable).

 

Since your IEnergyStorage implementation isn't actually storing the energy value itself, the ICapabilityProvider doesn't need to implement INBTSerializable (or ICapabilitySerializable, which is simply a combination of the two interfaces).

Edited by Choonster
  • Like 1

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

Thanks :) Now it works... kind of...

I did the Forge Energy implementation because EnderIO items can only be charged by Forge Energy or TESLA, even after the implementation my fluxpacks don't charge EnderIO items I don't know why... Is there a way to check if a capability is loaded correctly?

 

And I assume that I still can use the "normal" IEnergyContainerItem methods for energy usage, as I delegated them to the Capability in my EnergyConversionStorage

Posted (edited)
  On 4/17/2017 at 1:04 PM, Tomson124 said:

Thanks :) Now it works... kind of...

I did the Forge Energy implementation because EnderIO items can only be charged by Forge Energy or TESLA, even after the implementation my fluxpacks don't charge EnderIO items I don't know why... Is there a way to check if a capability is loaded correctly?

Expand  

 

You've exposed the IEnergyStorage capability on your own item, which allows other mods to insert/extract energy from it; but are you accessing the IEnergyStorage capability on the items you're trying to charge?

 

 

  Quote

And I assume that I still can use the "normal" IEnergyContainerItem methods for energy usage, as I delegated them to the Capability in my EnergyConversionStorage

Expand  

 

Yes, they'll still work.

Edited by Choonster

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
  On 4/17/2017 at 1:13 PM, Choonster said:

You've exposed the IEnergyStorage capability on your own item, which allows other mods to insert/extract energy from it; but are you accessing the IEnergyStorage capability on the items you're trying to charge?

Expand  

I assume that I don't do that, as I did no changes to the Item classe except overriding the initCapabilities... I thought I access the IEnergyStorage through the IEnergyContainerItem methods as they are delegated to the ForgeEnergy Capability, but probably I am understanding something wrong here.

How would I access the IEnergyStorage then? By using the ForgeEnergy methods? If so, how would I use them? just returning the IEnergyContainerITem method or calculating it again?

Posted
  On 4/17/2017 at 1:20 PM, Tomson124 said:

I assume that I don't do that, as I did no changes to the Item classe except overriding the initCapabilities... I thought I access the IEnergyStorage through the IEnergyContainerItem methods as they are delegated to the ForgeEnergy Capability, but probably I am understanding something wrong here.

How would I access the IEnergyStorage then? By using the ForgeEnergy methods? If so, how would I use them? just returning the IEnergyContainerITem method or calculating it again?

Expand  

 

All you've done is expose your own item's energy storage through the Forge Energy API, with an IEnergyStorage that calls the IEnergyContainerItem methods. This doesn't affect the energy stored in other items.

 

When you charge another item, you'll need to get its IEnergyStorage through the ItemStack's ICapabilityProvider methods and use IEnergyStorage#receiveEnergy to add energy to it. If it doesn't have one, check if it's an instance of IEnergyContainerItem and use the corresponding method to add energy to it. If it doesn't implement IEnergyContainerItem,

 

To simplify your code, you may want to create a method to get an IEnergyStorage from an ItemStack that does what I said above but returns an instance of EnergyConversionStorage if the item doesn't have an IEnergyStorage and implements IEnergyContainerItem. This way you can use IEnergyStorage#receiveEnergy regardless of which API the item supports.

 

You can use either API to extract energy from the Flux Pack (since you know they both use the same value).

  • Like 1

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

Thank you so much it is working now :)

I wrote a small method which returns the IEnergyStorage of the item which should be charged:

public IEnergyStorage getIEnergyStorage(ItemStack chargeItem) {

		if (chargeItem.hasCapability(CapabilityEnergy.ENERGY, null)) {
			return chargeItem.getCapability(CapabilityEnergy.ENERGY, null);
		}
		else if (chargeItem.getItem() instanceof IEnergyContainerItem) {
			return new EnergyConversionStorage((IEnergyContainerItem) chargeItem.getItem(), chargeItem);
		}

		return null;
}

I am reffering to that method when charging the Items, and it works perfectly fine. Just have to see if it also works with Items that do not implement ForgeEnergy, as I am not sure about that part:

else if (chargeItem.getItem() instanceof IEnergyContainerItem) {
	return new EnergyConversionStorage((IEnergyContainerItem) chargeItem.getItem(), chargeItem);
}

But thank you a lot, I now also have a much better knowledge of Capabilites, too. Thank you for your patience with me ^^

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • C:\Users\bruiser\curseforge\minecraft\Instances\Fazbear Remnants\essential\loader\stage1\launchwrapper\stage2.forge_1.12.2.jar: The process cannot access the file because it is being used by another process. Restart your system and test it again If there is no change, delete the mentioned essential folder or remove the mod essential
    • Does it work with newer versions? For 1.16.5 also make a test with Embeddium + Oculus as Optifine replacement
    • Looking for the best Temu coupon code $100 off? You’re in the right place! We’ve got the ultimate deal that helps you save big on your favorite items. Our exclusive ACS670886 Temu coupon code is perfect for shoppers in the USA, Canada, and Europe. Whether you're a new or existing customer, this code ensures you get maximum benefits. By using the Temu coupon $100 off, you can unlock exciting savings on Temu’s vast collection. Don’t miss this chance to claim your Temu 100 off coupon code today! What Is The Coupon Code For Temu $100 Off? Both new and existing customers can enjoy incredible benefits with our Temu coupon $100 off on the Temu app and website. This $100 off Temu coupon ensures huge savings for everyone! ACS670886 – Get a flat $100 off on selected purchases. ACS670886 – Unlock a $100 coupon pack for multiple uses. ACS670886 – Enjoy a $100 flat discount if you're a new customer. ACS670886 – Existing customers can claim an extra $100 promo code. ACS670886 – This $100 coupon is valid for shoppers in the USA and Canada. Temu Coupon Code $100 Off For New Users In 2025 New users can maximize their savings by applying our Temu coupon $100 off on the Temu app. This Temu coupon code $100 off unlocks amazing deals for first-time shoppers. ACS670886 – Get a flat $100 discount for new users. ACS670886 – Receive a $100 coupon bundle as a welcome offer. ACS670886 – Unlock up to $100 in coupons for multiple uses. ACS670886 – Enjoy free shipping to 68 countries. ACS670886 – Get an extra 30% off on any purchase as a first-time user. How To Redeem The Temu Coupon $100 Off For New Customers? Using the Temu $100 coupon is easy! Follow these steps to redeem your Temu $100 off coupon code for new users: Sign up on the Temu app or website. Browse and add your favorite items to the cart. Enter ACS670886 at checkout. See the $100 discount applied instantly. Complete your purchase and enjoy your savings! Temu Coupon $100 Off For Existing Customers Existing customers can also benefit from our exclusive Temu $100 coupon codes for existing users. Use this Temu coupon $100 off for existing customers free shipping deal and save more! ACS670886 – Get an extra $100 discount for existing users. ACS670886 – Enjoy a $100 coupon bundle for multiple purchases. ACS670886 – Receive a free gift with express shipping across the USA/Canada. ACS670886 – Grab an extra 30% off on top of existing discounts. ACS670886 – Avail free shipping to 68 countries. How To Use The Temu Coupon Code $100 Off For Existing Customers? Redeeming your Temu coupon code $100 off as an existing user is simple. Just follow these steps: Log in to your Temu account. Select your desired products and add them to your cart. Apply ACS670886 at checkout. Your Temu coupon $100 off code will be applied automatically. Confirm your order and enjoy massive savings! Latest Temu Coupon $100 Off First Order First-time buyers get the best deals with our Temu coupon code $100 off first order. This Temu coupon code first order ensures maximum savings. ACS670886 – Flat $100 discount for the first order. ACS670886 – Special $100 Temu coupon code for new customers. ACS670886 – Get up to $100 in coupons for multiple uses. ACS670886 – Free shipping to 68 countries. ACS670886 – Extra 30% off on any first-time purchase. How To Find The Temu Coupon Code $100 Off? Finding a Temu coupon $100 off is easy! Check out the Temu coupon $100 off Reddit section or follow these tips: Subscribe to the Temu newsletter for exclusive deals. Follow Temu’s official social media pages for the latest updates. Visit trusted coupon sites for verified and working codes. Is Temu $100 Off Coupon Legit? Yes, our Temu $100 Off Coupon Legit and verified! Wondering if the Temu 100 off coupon legit? Here’s why: The ACS670886 code is officially tested and confirmed. Valid for all customers in the USA, Canada, and Europe. No expiration date—use it anytime! How Does Temu $100 Off Coupon Work? The Temu coupon code $100 off first-time user works instantly upon applying at checkout. Simply enter the Temu coupon codes 100 off, and the discount is automatically deducted. How To Earn Temu $100 Coupons As A New Customer? To earn a Temu coupon code $100 off, sign up on Temu, make your first purchase, and refer friends. This 100 off Temu coupon code can be unlocked through special promotions. What Are The Advantages Of Using The Temu Coupon $100 Off? $100 discount on the first order $100 coupon bundle for multiple uses 70% discount on popular items Extra 30% off for existing customers Up to 90% off on selected products Free gifts for new users Free delivery to 68 countries Temu $100 Discount Code And Free Gift For New And Existing Customers Enjoy the Temu $100 off coupon code and get amazing benefits! Our $100 off Temu coupon code ensures huge savings. ACS670886 – $100 discount for the first order. ACS670886 – Extra 30% off on any item. ACS670886 – Free gift for new Temu users. ACS670886 – Up to 70% discount on all Temu items. ACS670886 – Free shipping in 68 countries including the USA and UK. Final Note: Use The Latest Temu Coupon Code $100 Off Using the Temu coupon code $100 off is the smartest way to save on Temu! Don’t wait—grab your discount now. Our Temu coupon $100 off is available for all customers, ensuring maximum savings. Get yours today! FAQs Of Temu $100 Off Coupon Q: How can I get the Temu $100 off coupon? A: Use code ACS670886 at checkout to claim your $100 discount. Q: Is the Temu $100 coupon valid for existing customers? A: Yes! Existing users can also apply ACS670886 and enjoy savings. Q: Does the Temu $100 off coupon have an expiration date? A: No, ACS670886 is valid indefinitely. Q: Can I use the Temu coupon on multiple orders? A: Yes! ACS670886 allows multiple redemptions. Q: Is the Temu $100 coupon applicable worldwide? A: Yes, it’s valid in the USA, Canada, Europe, and 68 other countries.
    • I tried both Vanilla and Optfine like you said, and both gave the same result. So I believe the issue is most likely with Minecraft in general and not Forge
    • https://pastebin.com/xWy0mWXA Like I said Modded Java Edition 1.12.2 using Forge Version 14.23.5.2859 Oh yeah and Exit Code: 1  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.