Search in sources :

Example 1 with EnergyStorage

use of net.minecraftforge.energy.EnergyStorage in project Overloaded by CJ-MC-Mods.

the class IntEnergyWrapper method deserializeNBT.

@Override
public void deserializeNBT(@Nullable NBTTagCompound nbt) {
    int energy = 0;
    if (nbt != null && nbt.hasKey("IntEnergyStorage")) {
        energy = nbt.getInteger("IntEnergyStorage");
    }
    storage = new EnergyStorage(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, energy);
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) EnergyStorage(net.minecraftforge.energy.EnergyStorage)

Example 2 with EnergyStorage

use of net.minecraftforge.energy.EnergyStorage in project Metalworks by canitzp.

the class TileBase method writeCapabilities.

protected void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
    IItemHandler inventory = this.getInventory(side);
    if (inventory != null && inventory instanceof IItemHandlerModifiable) {
        nbt.setTag("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side));
    }
    IFluidHandler tank = getTank(side);
    if (tank != null && tank instanceof IFluidTank) {
        nbt.setTag("FluidTank", CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side));
    }
    IEnergyStorage energy = getEnergy(side);
    if (energy != null && energy instanceof EnergyStorage) {
        nbt.setTag("Energy", CapabilityEnergy.ENERGY.writeNBT(energy, side));
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler) EnergyStorage(net.minecraftforge.energy.EnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 3 with EnergyStorage

use of net.minecraftforge.energy.EnergyStorage in project ICBM-Classic by BuiltBrokenModding.

the class EnergySystemFE method setEnergy.

@Override
public int setEnergy(Object object, EnumFacing side, int energy, boolean doAction) {
    IEnergyStorage storage = getCapability(object, side);
    if (storage != null) {
        int energyLimited = Math.max(0, Math.min(storage.getMaxEnergyStored(), energy));
        // Edge case work around to help remove all energy, yes this will need to be done per mod
        if (storage instanceof EnergyStorage) {
            if (!failedenergyStorageField) {
                try {
                    if (energyStorageField == null) {
                        energyStorageField = EnergyStorage.class.getDeclaredField("energy");
                        energyStorageField.setAccessible(true);
                    }
                    energyStorageField.setInt(storage, energyLimited);
                } catch (Exception ex) {
                    failedenergyStorageField = true;
                    ICBMClassic.logger().error("Failed to access EnergyStorage#energy to set energy value directly", ex);
                }
            }
        }
        return removeEnergy(object, side, Integer.MAX_VALUE, doAction);
    }
    return 0;
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) EnergyStorage(net.minecraftforge.energy.EnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage)

Example 4 with EnergyStorage

use of net.minecraftforge.energy.EnergyStorage in project Overloaded by CJ-MC-Mods.

the class TileMatterPurifier method load.

@Override
public void load(@Nonnull BlockState state, @Nonnull CompoundNBT compound) {
    super.load(state, compound);
    // fluidStorage.readFromNBT((CompoundNBT) compound.get("Fluid"));
    energyStorage = new EnergyStorage(compound.getInt("Energy"), Integer.MAX_VALUE, Integer.MAX_VALUE);
}
Also used : EnergyStorage(net.minecraftforge.energy.EnergyStorage)

Example 5 with EnergyStorage

use of net.minecraftforge.energy.EnergyStorage in project Overloaded by CJ-MC-Mods.

the class IntEnergyWrapper method getStorage.

@Nonnull
private EnergyStorage getStorage() {
    if (stack.getTag() == null) {
        Overloaded.logger.error((CharSequence) "Something has changed private internal state in an invalid way. Resetting State.", new IllegalStateException("private internal state changed. Stack's Tag Compound is null"));
        stack.setTag(new CompoundNBT());
    }
    int energy = stack.getTag().getInt("IntEnergyStorage");
    return new EnergyStorage(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, energy);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) EnergyStorage(net.minecraftforge.energy.EnergyStorage) Nonnull(javax.annotation.Nonnull)

Aggregations

EnergyStorage (net.minecraftforge.energy.EnergyStorage)7 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)6 Nonnull (javax.annotation.Nonnull)2 IFluidTank (net.minecraftforge.fluids.IFluidTank)2 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2 Nullable (javax.annotation.Nullable)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 Capability (net.minecraftforge.common.capabilities.Capability)1 ICapabilityProvider (net.minecraftforge.common.capabilities.ICapabilityProvider)1