use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class TileEnergyExtractor method update.
/**
* Like the old updateEntity(), except more generic.
*/
@Override
public void update() {
BlockPos me = this.getPos();
TileEntity frontTE = getWorld().getTileEntity(me.add(front.getDirectionVec()));
if (frontTE == null || !frontTE.hasCapability(HYPER_ENERGY_HANDLER, front.getOpposite()))
return;
IHyperHandlerEnergy storage = frontTE.getCapability(HYPER_ENERGY_HANDLER, front.getOpposite());
LongEnergyStack energy = storage.take(new LongEnergyStack(Long.MAX_VALUE), false);
for (EnumFacing facing : EnumFacing.values()) {
if (energy.getAmount() == 0L)
return;
if (facing == front)
continue;
TileEntity te = world.getTileEntity(me.add(facing.getDirectionVec()));
if (te == null || !te.hasCapability(ENERGY, facing.getOpposite()))
continue;
IEnergyStorage receiver = te.getCapability(ENERGY, facing.getOpposite());
if (!receiver.canReceive())
continue;
int acceptedAmount = receiver.receiveEnergy((int) Math.min(energy.getAmount(), Integer.MAX_VALUE), true);
if (acceptedAmount != 0) {
receiver.receiveEnergy(acceptedAmount, false);
energy = storage.take(new LongEnergyStack(acceptedAmount), true);
}
}
}
Aggregations