MachineMuse / MachineMusePowersuits

Minecraft mod, take 2
236 stars 105 forks source link

Fixed Mekanism tools reporting having power while being undrainable. #806

Closed bluewave41 closed 7 years ago

bluewave41 commented 7 years ago

Chargeable Mekanism tools like the Atomic Disassembler report having power available but are marked as being unable to transfer power resulting in infinite powersuit power if carrying them.

lehjr commented 7 years ago

Thanks. I'll put out a new build in the morning.

lehjr commented 7 years ago

I really should have looked more closely at this. This doesn't work because "instanceof IEnergizedItem" is the qualifier to use power from the item, but MekanismElectricAdapter is using "IEnergyContainerItem" which won't work, plus converting to RF and back is unnecessary since MPS is already using MJ at a 1:1 ratio with Mekanism.

bluewave41 commented 7 years ago

Well here let me explain what I was going for because it does work but maybe it isn't the best method.

Before: https://puu.sh/weyLV/079683ddf4.png After: https://puu.sh/weyQU/2dda6e328a.png

I casted the item through MekanismElectricAdapter.getEnergy (maybe an instance variable is better?) TEElectricAdapter works except for the fact that Mekanism's implementation of extractEnergy checks if the item is capable of extracting or not.

public double getCurrentEnergy() {
    IEnergizedItem item = (IEnergizedItem)this.stack.getItem();
    return item.canSend(this.stack) ? ElectricConversions.museEnergyFromRF(this.item().getEnergyStored(this.stack())) : 0;
}

Atomic Disassembler class: https://github.com/aidancbrady/Mekanism/blob/master/src/main/java/mekanism/common/item/ItemAtomicDisassembler.java

public int extractEnergy(ItemStack theItem, int energy, boolean simulate)
{
    if(canSend(theItem))
    {
        double energyRemaining = getEnergy(theItem);
        double toSend = Math.min((energy*general.FROM_RF), energyRemaining);

        if(!simulate)
        {
            setEnergy(theItem, getEnergy(theItem) - toSend);
        }

        return (int)Math.round(toSend*general.TO_RF);
    }

    return 0;
}

@Override
public boolean canSend(ItemStack itemStack)
{
    return false;
}

So I figured the easiest fix then being the class works is to just return 0 energy if it can't send any which worked great.

Also I'm not sure about the RF conversion comments unless I'm misunderstanding something, Mekanism uses J which converts to .1EU, .4RF and 0.4MJ. I made sure to check that getEnergy for a Basic Energy Cube holding 2M J converts down to 800,000RF which looks to work properly to me so I kept the other methods the same.

lehjr commented 7 years ago

Again, in ElectricAdapter.java you're checking for an instance of IEnergizedItem, but in MekanismElectricAdapter.java you're declaring it as an instance of IEnergyContainerItem which the item is not and could cause a crash if there is no RF power API available.

As far as the conversion to and from RF, as I said, the calculations are unnecessary because MPS already uses a 1:1 ratio with Mekanism's power.

I've addressed this in commit 84ee299fa0d9a6a7cf480032e8971da8f93975c5, but MuseStringUtils needs to be updated to handle the energy cubes.

lehjr commented 7 years ago

Ok, not all energy cubes, just the creative one.