Integrated Dynamics

Integrated Dynamics

63M Downloads

Power Dupe with Energy Battery

NielsPilgaard opened this issue ยท 9 comments

commented

Issue type:

  • ๐Ÿ› Bug

Short description:

Since Energy Batteries stack, you can put a stack of them in a charging block* and they will all be filled at the same time. The power drained will be the capacity of 1 Energy Battery, making it possible to dupe energy up to 64x

*such as the Mekanism Energy Cube

Steps to reproduce the problem:

  1. Make an instance with ID and Mekanism
  2. Make a world
  3. Put down a full Advanced Energy Cube
  4. Put a stack of Energy Batteries in it
  5. See error

Expected behaviour:

For the batteries not to be stackable I guess?
No energy dupe at least ๐Ÿ˜„


Versions:

  • This mod: IntegratedDynamics-1.16.5-1.10.2
  • Minecraft: 1.16.5
  • Forge: 1.16.5-36.2.4

Log file:

commented

Thanks for reporting!

commented

Not sure this is really an ID issue. It makes sense to have containers stack, just like vanilla empty buckets stack. But just like with empty buckets, machines have to make sure that during filling only one item at a time is filled.
So this seems like a bug/flaw in Mekanism to me.

commented

Fair enough ๐Ÿ˜„

commented

No idea how many mods do the check (they should do it in any case). All my mods do it :-)

commented

Hmm, that's a good point. I think the vast majority of mods capable of charging items don't check for stack size though.

commented

I do agree that a good portion of this is related to how capabilities work in that if you expose a capability on a stacked stack it will end up mutating all of the stack (and this is why the vast majority of mods I am aware of don't allow their tanks or batteries to be stacked, or if they do they don't provide a capability when it is stacked/NO-OP the capability). The big difference here is that unlike how forge has a specialized fluid handler item that returns what the container is that can then be used to check for stackability of things, there is no such specialized version for energy handlers.

Personally I think a better solution for mods like ID that have items that can stack and expose a capability that can be interacted with even when an item is stacked would be to more or less have the item capability have the methods do something like:

public int receiveEnergy(int maxReceive, boolean simulate) {
    int stackSize = stack.getCount();
    //Ensure we don't accept more than we can distribute between the stack
    int perBattery = maxReceive / stackSize;
    if (perBattery == 0) {
        //Less energy is being provided than how many batteries we have
        return 0;
    }
    //Do normal logic here for amount of room there is making use of perBattery
    return perBattery * stackSize;
}

This way any mods like Mekanism which do accept stacks if you let your item stack or even mods that charge a player's inventory will interact as expected.

commented

Hmm, I hadn't thought of that. Including a stacksize check in the receive/extract methods may actually be a good idea, as it still allows stacking of batteries. I'll re-open this one.

Note to self: modify EnergyStorageItemBlockEnergyContainer

commented

Depending on how ID handles rate limits it may also be wise to adjust the returned values for getEnergyStored and getMaxEnergyStored as well to be the sum of the batteries just so that if say it effectively returns there is 1 FE needed, then if a mod only tries to send that 1 FE it isn't able to accept it because of needing 2 FE because there are two batteries that each need 1 FE.

commented

Thanks, both of you :D ๐ŸŽ‰