Search in sources :

Example 1 with IEnergyTransfer

use of mods.railcraft.api.carts.IEnergyTransfer in project Railcraft by Railcraft.

the class TileIC2Loader method processCart.

@Override
protected void processCart(EntityMinecart cart) {
    IEnergyTransfer energyCart = (IEnergyTransfer) cart;
    if (energy > 0 && energyCart.getEnergy() < energyCart.getCapacity()) {
        double usage = (int) (energyCart.getTransferLimit() * Math.pow(1.5, overclockerUpgrades));
        double injection = (int) (energyCart.getTransferLimit() * Math.pow(1.3, overclockerUpgrades));
        if (usage > energy) {
            double ratio = (double) energy / usage;
            usage = energy;
            injection = (int) (injection * ratio);
        }
        transferRate = (int) injection;
        double extra = energyCart.injectEnergy(this, injection, getTier(), true, false, false);
        energy -= usage - extra;
        setProcessing(extra != injection);
    }
}
Also used : IEnergyTransfer(mods.railcraft.api.carts.IEnergyTransfer)

Example 2 with IEnergyTransfer

use of mods.railcraft.api.carts.IEnergyTransfer in project Railcraft by Railcraft.

the class CartBaseEnergy method injectEnergy.

@Override
public double injectEnergy(Object source, double amount, int tier, boolean ignoreTransferLimit, boolean simulate, boolean passAlong) {
    if (tier < getTier())
        return amount;
    double extra = 0;
    if (!ignoreTransferLimit) {
        extra = Math.max(amount - getTransferLimit(), 0);
        amount = Math.min(amount, getTransferLimit());
    }
    double e = getEnergy() + amount;
    int capacity = getCapacity();
    if (e > capacity) {
        extra += e - capacity;
        e = capacity;
    }
    if (!simulate)
        setEnergy(e);
    if (!passAlong)
        return extra;
    try {
        ILinkageManager lm = CartToolsAPI.getLinkageManager(worldObj);
        EntityMinecart linkedCart = lm.getLinkedCartA(this);
        if (extra > 0 && linkedCart != source && linkedCart instanceof IEnergyTransfer)
            extra = ((IEnergyTransfer) linkedCart).injectEnergy(this, extra, tier, ignoreTransferLimit, simulate, true);
        linkedCart = lm.getLinkedCartB(this);
        if (extra > 0 && linkedCart != source && linkedCart instanceof IEnergyTransfer)
            extra = ((IEnergyTransfer) linkedCart).injectEnergy(this, extra, tier, ignoreTransferLimit, simulate, true);
    } catch (Throwable t) {
        APIErrorHandler.versionMismatch(IEnergyTransfer.class);
    }
    return extra;
}
Also used : ILinkageManager(mods.railcraft.api.carts.ILinkageManager) IEnergyTransfer(mods.railcraft.api.carts.IEnergyTransfer) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 3 with IEnergyTransfer

use of mods.railcraft.api.carts.IEnergyTransfer in project Railcraft by Railcraft.

the class CartBaseEnergy method extractEnergy.

@Override
public double extractEnergy(Object source, double amount, int tier, boolean ignoreTransferLimit, boolean simulate, boolean passAlong) {
    if (tier < getTier())
        return 0;
    if (!ignoreTransferLimit)
        amount = Math.min(amount, getTransferLimit());
    double e = getEnergy();
    double provide = Math.min(amount, e);
    e -= provide;
    if (e < 0)
        e = 0;
    if (!simulate)
        setEnergy(e);
    if (!passAlong)
        return provide;
    ILinkageManager lm = CartToolsAPI.getLinkageManager(worldObj);
    EntityMinecart linkedCart = lm.getLinkedCartA(this);
    if (provide < amount && linkedCart != source && linkedCart instanceof IEnergyTransfer)
        provide += ((IEnergyTransfer) linkedCart).extractEnergy(this, amount - provide, tier, ignoreTransferLimit, simulate, true);
    linkedCart = lm.getLinkedCartB(this);
    if (provide < amount && linkedCart != source && linkedCart instanceof IEnergyTransfer)
        provide += ((IEnergyTransfer) linkedCart).extractEnergy(this, amount - provide, tier, ignoreTransferLimit, simulate, true);
    return provide;
}
Also used : ILinkageManager(mods.railcraft.api.carts.ILinkageManager) IEnergyTransfer(mods.railcraft.api.carts.IEnergyTransfer) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 4 with IEnergyTransfer

use of mods.railcraft.api.carts.IEnergyTransfer in project Railcraft by Railcraft.

the class TileIC2Unloader method processCart.

@Override
protected void processCart(EntityMinecart cart) {
    IEnergyTransfer energyCart = (IEnergyTransfer) cart;
    if (energy < getCapacity() && energyCart.getEnergy() > 0) {
        double usage = (energyCart.getTransferLimit() * Math.pow(1.5, overclockerUpgrades));
        double injection = (energyCart.getTransferLimit() * Math.pow(1.3, overclockerUpgrades));
        double room = getCapacity() - getEnergy();
        if (room < injection) {
            double ratio = room / injection;
            injection = room;
            usage = usage * ratio;
        }
        double extract = energyCart.extractEnergy(this, usage, getTier(), true, false, false);
        if (extract < usage) {
            double ratio = extract / usage;
            //                usage = extract;
            injection = injection * ratio;
        }
        transferRate = (int) injection;
        energy += injection;
        setProcessing(extract > 0);
    }
}
Also used : IEnergyTransfer(mods.railcraft.api.carts.IEnergyTransfer)

Aggregations

IEnergyTransfer (mods.railcraft.api.carts.IEnergyTransfer)4 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2