Search in sources :

Example 1 with IEnergyStorage

use of ic2.api.tile.IEnergyStorage in project TUMAT by canitzp.

the class ElectricalUnits method renderTileEntity.

@Override
public TooltipComponent renderTileEntity(WorldClient world, EntityPlayerSP player, TileEntity tileEntity, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    if (ConfigBoolean.SHOW_EU.value && tileEntity instanceof IEnergyStorage) {
        InfoUtil.syncTileEntity(tileEntity, shouldCalculate, "components");
        int current = ((IEnergyStorage) tileEntity).getStored();
        int capacity = ((IEnergyStorage) tileEntity).getCapacity();
        if (capacity > 0) {
            component.add(new EnergyComponent(current, capacity, "EU", TextFormatting.YELLOW), TooltipComponent.Priority.HIGH);
        }
    }
    return component;
}
Also used : IEnergyStorage(ic2.api.tile.IEnergyStorage) EnergyComponent(de.canitzp.tumat.api.components.EnergyComponent)

Example 2 with IEnergyStorage

use of ic2.api.tile.IEnergyStorage in project Flux-Networks by SonarSonic.

the class EnergyUnitsHandler method addEnergy.

@Override
public long addEnergy(long add, TileEntity tile, EnumFacing dir, ActionType actionType) {
    if (tile instanceof IEnergyStorage) {
        IEnergyStorage sink = (IEnergyStorage) tile;
        int before = sink.getStored();
        if (!actionType.shouldSimulate()) {
            return sink.addEnergy((int) Math.min(sink.getCapacity() - before, add));
        } else {
            return Math.min(sink.getCapacity() - before, add);
        }
    } else if (tile instanceof IEnergySink) {
        IEnergySink sink = (IEnergySink) tile;
        double voltage = EnergyNet.instance.getPowerFromTier(sink.getSinkTier());
        double amount = Math.min(add, voltage);
        if (actionType.shouldSimulate()) {
            return (long) Math.min(amount, sink.getDemandedEnergy());
        } else {
            return (long) Math.floor(amount - sink.injectEnergy(dir, amount, voltage));
        }
    }
    return 0;
}
Also used : IEnergyStorage(ic2.api.tile.IEnergyStorage) IEnergySink(ic2.api.energy.tile.IEnergySink)

Example 3 with IEnergyStorage

use of ic2.api.tile.IEnergyStorage in project TUMAT by canitzp.

the class IndustrialCraft2 method renderTileEntity.

@Override
public TooltipComponent renderTileEntity(WorldClient world, EntityPlayerSP player, TileEntity tileEntity, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    if (tileEntity instanceof TileEntityBlock) {
        InfoUtil.syncTileEntity(tileEntity, shouldCalculate, "components");
        if (((TileEntityBlock) tileEntity).hasComponent(Energy.class)) {
            Energy energy = ((TileEntityBlock) tileEntity).getComponent(Energy.class);
            List<String> desc = new ArrayList<>();
            if (ConfigBoolean.SHOW_EU.value) {
                if (!(tileEntity instanceof IEnergyStorage)) {
                    int stored = (int) energy.getEnergy();
                    int cap = (int) energy.getCapacity();
                    if (cap > 0) {
                        if (cap < stored) {
                            cap = stored;
                        }
                        component.add(new EnergyComponent(stored, cap, "EU", TextFormatting.YELLOW), TooltipComponent.Priority.HIGH);
                    }
                }
                if (!energy.getSourceDirs().isEmpty()) {
                    desc.add(Localization.translate("ic2.item.tooltip.PowerTier", energy.getSourceTier()));
                } else if (!energy.getSinkDirs().isEmpty()) {
                    desc.add(Localization.translate("ic2.item.tooltip.PowerTier", energy.getSinkTier()));
                }
            }
            if (tileEntity instanceof TileEntityTransformer) {
                desc.add(String.format("%s %.0f %s %s %.0f %s", Localization.translate("ic2.item.tooltip.Low"), EnergyNet.instance.getPowerFromTier(energy.getSinkTier()), Localization.translate("ic2.generic.text.EUt"), Localization.translate("ic2.item.tooltip.High"), EnergyNet.instance.getPowerFromTier(energy.getSourceTier() + 1), Localization.translate("ic2.generic.text.EUt")));
            }
            component.clear(TooltipComponent.Priority.LOW);
            component.add(new DescriptionComponent(desc), TooltipComponent.Priority.LOW);
        }
    }
    if (tileEntity instanceof TileEntityCable) {
        InfoUtil.syncTileEntity(tileEntity, shouldCalculate, "cableType", "insulation");
        NBTTagCompound nbt = new NBTTagCompound();
        tileEntity.writeToNBT(nbt);
        if (!nbt.hasNoTags()) {
            try {
                CableType cableType = CableType.values[nbt.getByte("cableType") & 255];
                int insulation = nbt.getByte("insulation") & 255;
                ItemStack cable = ItemCable.getCable(cableType, insulation);
                component.setName(new TextComponent(InfoUtil.getItemName(cable)));
                component.clear(TooltipComponent.Priority.LOW);
                component.add(new DescriptionComponent(cable), TooltipComponent.Priority.LOW);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) TileEntityCable(ic2.core.block.wiring.TileEntityCable) TileEntityTransformer(ic2.core.block.wiring.TileEntityTransformer) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnergyComponent(de.canitzp.tumat.api.components.EnergyComponent) Energy(ic2.core.block.comp.Energy) CableType(ic2.core.block.wiring.CableType) IEnergyStorage(ic2.api.tile.IEnergyStorage) TileEntityBlock(ic2.core.block.TileEntityBlock) ItemStack(net.minecraft.item.ItemStack) DescriptionComponent(de.canitzp.tumat.api.components.DescriptionComponent)

Aggregations

IEnergyStorage (ic2.api.tile.IEnergyStorage)3 EnergyComponent (de.canitzp.tumat.api.components.EnergyComponent)2 DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)1 TextComponent (de.canitzp.tumat.api.components.TextComponent)1 IEnergySink (ic2.api.energy.tile.IEnergySink)1 TileEntityBlock (ic2.core.block.TileEntityBlock)1 Energy (ic2.core.block.comp.Energy)1 CableType (ic2.core.block.wiring.CableType)1 TileEntityCable (ic2.core.block.wiring.TileEntityCable)1 TileEntityTransformer (ic2.core.block.wiring.TileEntityTransformer)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1