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);
}
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));
}
}
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;
}
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);
}
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);
}
Aggregations