use of net.minecraftforge.fluids.IFluidHandler in project TechReborn by TechReborn.
the class MultipartFluidPipe method update.
@Override
public void update() {
if (!getWorld().isRemote) {
for (EnumFacing dir : EnumFacing.VALUES) {
// if (connectedSides.containsKey(dir)) {
MultipartFluidPipe fluidPipe = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if (fluidPipe != null) {
if (!tank.isEmpty()) {
if (fluidPipe.tank.isEmpty() || fluidPipe.tank.getFluid().getFluid() == tank.getFluid().getFluid()) {
if (fluidPipe.tank.getFluidAmount() < tank.getFluidAmount()) {
int freeSpace = fluidPipe.tank.getCapacity();
if (!fluidPipe.tank.isEmpty()) {
freeSpace = fluidPipe.tank.getCapacity() - fluidPipe.tank.getFluidAmount();
}
int difference = tank.getFluidAmount() - freeSpace;
int amountToChange = difference / 2;
fluidPipe.tank.setFluid(tank.getFluid());
fluidPipe.tank.setFluidAmount(fluidPipe.tank.getFluidAmount() + amountToChange);
tank.setFluidAmount(tank.getFluidAmount() - amountToChange);
}
}
}
}
// }
TileEntity tileEntity = getNeighbourTile(dir);
if (tileEntity != null) {
if (tileEntity instanceof IFluidHandler) {
IFluidHandler handler = (IFluidHandler) tileEntity;
if (getPipeType() == EnumFluidPipeTypes.EXTRACT) {
if (!tank.isFull()) {
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
if (fluidTankInfos.length != 0) {
FluidTankInfo info = fluidTankInfos[0];
if (info != null & info.fluid != null) {
if (tank.isEmpty() || info.fluid.getFluid() == tank.getFluid().getFluid()) {
if (handler.canDrain(dir.getOpposite(), info.fluid.getFluid())) {
int amountToMove = Math.min(mbt, tank.getCapacity() - tank.getFluidAmount());
int fluidAmount = tank.getFluidAmount();
FluidStack fluidStack = handler.drain(dir.getOpposite(), amountToMove, true);
tank.fill(fluidStack, true);
tank.setFluid(fluidStack);
tank.setFluidAmount(fluidAmount + amountToMove);
}
}
}
}
}
} else if (getPipeType() == EnumFluidPipeTypes.INSERT) {
if (!tank.isEmpty()) {
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
if (fluidTankInfos.length != 0) {
FluidTankInfo info = fluidTankInfos[0];
if (info.fluid == null || info.fluid.getFluid() == null || info.fluid.getFluid() == tank.getFluid().getFluid() && handler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
int infoSpace = info.capacity;
if (info.fluid != null) {
infoSpace = info.capacity - info.fluid.amount;
}
int amountToMove = Math.min(mbt, infoSpace);
FluidStack fluidStack = tank.drain(amountToMove, true);
handler.fill(dir.getOpposite(), fluidStack, true);
}
}
}
}
}
}
}
}
}
Aggregations