Addon power drawing problem

  • Hey people,


    I've worked on an addon for IC2, and I've put it on my server, and it appeared to be working correctly, though now there's a problem when someone places my block, it will draw power from attached cables / generators, though,
    when my friend had a generator below it, which was fully filled with EU, and my block had consumed some EU, it wouldn't suck up more energy.


    I can't figure out what I'm doing wrong by looking at my code so if anyone can, you're my hero :)


    Here's the code ( implements IEnergySink from the API :( http://pastebin.com/nNZhrvdW


    edit: fixed link

  • Fixed link, also I just noticed in the injectEnergy method, I've got it checking if the side isn't up, then add... I just changed this to:


    if (directionFrom.equals(Direction.YM))


    since I only want power from bottom

  • Hmm. I note an odd possible bug: if injectEnergy is called with an amount < 4 while you have less than 10,000 EU stored, you return a negative number. I have no idea what the EnergyNet does when you do that, but it might be what's causing your issue here. Here, check my mental steps for injectEnergy(Direction.YN, 3):


    Again, I'm not sure if this is the problem, but otherwise it seems to do what you seem to want it to (which is to accept only 4 EU at a time, no matter how much was actually sent to you, until you have a buffer of 10,000 EU exactly).


    Swapping the return for

    Code
    return ((left < 0) ? 0 : left)

    should do the job.

  • Thanks, this fixed a bug which kept drawing power from the power source, though I still had to update the cable from the bottom to get it to draw power again.