2017-04-10 16:20:39 +02:00
|
|
|
/*
|
2016-12-20 17:05:20 +01:00
|
|
|
* This file is part of Industrial Wires.
|
2017-04-10 16:20:39 +02:00
|
|
|
* Copyright (C) 2016-2017 malte0811
|
2016-12-20 17:05:20 +01:00
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-10 16:20:39 +02:00
|
|
|
*/
|
2016-12-19 18:16:46 +01:00
|
|
|
package malte0811.industrialWires.blocks;
|
|
|
|
|
|
|
|
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxConnection;
|
|
|
|
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider;
|
|
|
|
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
|
|
|
|
|
|
|
public class EnergyAdapter implements IEnergyStorage {
|
|
|
|
/**
|
2017-05-10 17:56:05 +02:00
|
|
|
* 2 different copies of the same thing, the TE this adapter is mirroring.
|
2016-12-19 18:16:46 +01:00
|
|
|
* rec and prov are null if the TE does not implement them
|
|
|
|
*/
|
2017-05-10 17:56:05 +02:00
|
|
|
private IFluxReceiver rec;
|
|
|
|
private IFluxProvider prov;
|
|
|
|
|
|
|
|
private EnumFacing dir;
|
2016-12-19 18:16:46 +01:00
|
|
|
public EnergyAdapter(IFluxConnection te, EnumFacing f) {
|
|
|
|
dir = f;
|
|
|
|
if (te instanceof IFluxReceiver) {
|
|
|
|
rec = (IFluxReceiver) te;
|
|
|
|
}
|
|
|
|
if (te instanceof IFluxProvider) {
|
|
|
|
prov = (IFluxProvider) te;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int receiveEnergy(int maxReceive, boolean simulate) {
|
|
|
|
if (rec==null) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return rec.receiveEnergy(dir, maxReceive, simulate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int extractEnergy(int maxExtract, boolean simulate) {
|
|
|
|
if (prov==null) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return prov.extractEnergy(dir, maxExtract, simulate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyStored() {
|
|
|
|
if (prov!=null) {
|
|
|
|
return prov.getEnergyStored(dir);
|
|
|
|
} else if (rec!=null) {
|
|
|
|
return rec.getEnergyStored(dir);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored() {
|
|
|
|
if (prov!=null) {
|
|
|
|
return prov.getMaxEnergyStored(dir);
|
|
|
|
} else if (rec!=null) {
|
|
|
|
return rec.getMaxEnergyStored(dir);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtract() {
|
|
|
|
return prov!=null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canReceive() {
|
|
|
|
return rec!=null;
|
|
|
|
}
|
|
|
|
}
|